Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Poll: Was this helpful to you?
You do not have permission to vote in this poll.
Yes
33.33%
1 33.33%
No
66.67%
2 66.67%
Total 3 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding on Global Variables and how to use them.
Wooderson Offline
Posting Freak

Posts: 2,460
Threads: 25
Joined: Dec 2011
Reputation: 52
#11
RE: Understanding on Global Variables and how to use them.

(03-27-2013, 03:16 PM)JustAnotherPlayer Wrote:
(03-27-2013, 03:14 PM)Wooderson Wrote: Learning about functions and procedures in A Level Computing at the moment (VB).

I am in no way a pro or anything, I am very amateur but this is what I know about them.

They will make your sub main shorter as you call each procedure/function within sub main which is at a different part of the program.

Main benefit is its easier to test for bugs.
Disadvantage is you need to look out for variables and such being local/global and re-used etc.

I think your in the wrong thread here.

Wouldn't surprise me at all since I am shit at computing and such. Global/Local variables are to do with functions/procedures though right?

[Image: luv.gif]
03-27-2013, 03:17 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#12
RE: Understanding on Global Variables and how to use them.

(03-27-2013, 03:17 PM)Wooderson Wrote:
(03-27-2013, 03:16 PM)JustAnotherPlayer Wrote:
(03-27-2013, 03:14 PM)Wooderson Wrote: Learning about functions and procedures in A Level Computing at the moment (VB).

I am in no way a pro or anything, I am very amateur but this is what I know about them.

They will make your sub main shorter as you call each procedure/function within sub main which is at a different part of the program.

Main benefit is its easier to test for bugs.
Disadvantage is you need to look out for variables and such being local/global and re-used etc.

I think your in the wrong thread here.

Wouldn't surprise me at all since I am shit at computing and such. Global/Local variables are to do with functions/procedures though right?


Your right in some ways, but you gotta be careful with the local/global variables you learn about in programming languages and what they mean in Amnesia scripting. I tripped up on it at one point and got YC to explain it.

The problem is that global/local in programming is referring to the scope, which is why it's relevant to functions and procedures. In a C style language, a change of scope is always denoted by using {}, that counts for functions as well as if/while/do/for statements & loops. VB is slightly different in that it uses 'if...end if' rather than 'if { ... }'

int inThisIsAGlobalVariable; // because it is outside of the scope of a function

void OnStart() {
     int inThisIsALocalVariable; // because it is only relevant to the scope of OnStart, cannot be used outside
}

void function() {
     inThisIsAGlobalVariable = 2; // this variable can be used, because it has been declared in the global scope (outside any functions/statements)
     inThisIsALocalVariable = 2; // this will cause an error, because you are no longer inside the scope of OnStart
}

The way I was taught in C, was to never ever use global variables - you never need to use them because other options are available, and they cause unnecessary difficulty debugging if you're unexpectedly setting the value somewhere you can't remember. I use them in scripts though, because they are incredibly useful Tongue Just make sure you name them in a unique way, so you'll never accidentally use it.

Neither of the variables in the code above will be saved by the game if the player saves & exits, they all get wiped out. All except for the variables declared with the functions SetLocalVar... and SetGlobalVar..., those variables are correctly saved by HPL2
In terms of those functions, Local is referring to the whole .hps file you are using (regardless of the scope when declared), and Global means available in all the script files.

Hope that helps clear things up, if you want any further explanation please ask Smile

(This post was last modified: 03-27-2013, 11:19 PM by Adrianis.)
03-27-2013, 11:14 PM
Find
Wooderson Offline
Posting Freak

Posts: 2,460
Threads: 25
Joined: Dec 2011
Reputation: 52
#13
RE: Understanding on Global Variables and how to use them.

Yeah I've never used anything other than VB for programming, just testing what I already know.

The HPL2 looks pretty confusing to me.

[Image: luv.gif]
03-28-2013, 09:04 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#14
RE: Understanding on Global Variables and how to use them.

(03-28-2013, 09:04 AM)Wooderson Wrote: Yeah I've never used anything other than VB for programming, just testing what I already know.

The HPL2 looks pretty confusing to me.
HPL2 doesn't look that confusing to me.

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-28-2013, 11:41 AM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#15
RE: Understanding on Global Variables and how to use them.

(03-28-2013, 11:41 AM)JustAnotherPlayer Wrote:
(03-28-2013, 09:04 AM)Wooderson Wrote: Yeah I've never used anything other than VB for programming, just testing what I already know.

The HPL2 looks pretty confusing to me.
HPL2 doesn't look that confusing to me.

It doesn't look confusing to me either, but as you may have experience, Wooderson doesn't have that much (or doesn't have).

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
03-28-2013, 12:11 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#16
RE: Understanding on Global Variables and how to use them.

(03-28-2013, 12:11 PM)The chaser Wrote:
(03-28-2013, 11:41 AM)JustAnotherPlayer Wrote:
(03-28-2013, 09:04 AM)Wooderson Wrote: Yeah I've never used anything other than VB for programming, just testing what I already know.

The HPL2 looks pretty confusing to me.
HPL2 doesn't look that confusing to me.

It doesn't look confusing to me either, but as you may have experience, Wooderson doesn't have that much (or doesn't have).
Yeah, maybe Wooderson doesn't have much. I started out having zero experience. Three months later, and here i am!

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-28-2013, 12:15 PM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#17
RE: Understanding on Global Variables and how to use them.

(03-28-2013, 12:15 PM)JustAnotherPlayer Wrote:
(03-28-2013, 12:11 PM)The chaser Wrote:
(03-28-2013, 11:41 AM)JustAnotherPlayer Wrote:
(03-28-2013, 09:04 AM)Wooderson Wrote: Yeah I've never used anything other than VB for programming, just testing what I already know.

The HPL2 looks pretty confusing to me.
HPL2 doesn't look that confusing to me.

It doesn't look confusing to me either, but as you may have experience, Wooderson doesn't have that much (or doesn't have).
Yeah, maybe Wooderson doesn't have much. I started out having zero experience. Three months later, and here i am!

I started in... July? So, I made my CS and at this time I can assure you that I have learnt a lot. Just have it present: You can never know everything about the editor, there will always be things to learn.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
03-28-2013, 02:30 PM
Find




Users browsing this thread: 1 Guest(s)