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.
PutraenusAlivius Offline
Posting Freak

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

What are global variables? They are variables that are global, which means if you do something on one map, something on another one does something else.
EXAMPLE:
In map 1 you fixed a machinery. In map 3, a door will be lifted because the machinery is done.
END EXAMPLE.

Here's how you do it.
(NOTE: THE global.hps MUST BE IN YOUR MAPS/ DIRECTORY!)
1. Make a global.hps file (EXTENSION MUST BE .HPS!)
---
2. Type this on the global.hps
---
PHP Code: (Select All)
void OnGameStart()
{
SetGlobalVarInt("NAME"0);  //Change NAME to whatever you want the name to be.

Get it? This means that on Game Start (When the player plays the game first time. Not entering map first time)SetGlobalVarInt will set it's variable to 0.
---
3. In the map where the player must do something to do something else in another map, wrote this to the map's .hps file.
This must be in another function!
PHP Code: (Select All)
AddGlobalVarInt("NAME"1);  //Change NAME to whatever you want the name to be. 
Get it? This means that if the Player does something, it will add the GlobalVarInt to 1.
---
4. In the map where you want something to do if the player has done something from another map, wrote this the the map's .hps file.
---
PHP Code: (Select All)
void OnEnter()
{
    if(
GetGlobalVarInt("NAME") == 1
       {
        
//Something changed if Player added the GlobalVarInt.
       
}

Get it? No? Fine. This means each time Player enters the map, the if-statement will check whether GlobalVarInt is 1 or not. If it's 1, it will do something. But if it didn't, it would do nothing.
Hope this helps. If there's another thread for this, i'm deeply sorry for not noticing it. It's directed for people who didn't knew Global Variables.
---
For Local Variables, change Global to Local on each function. Like GetGlobalVarInt to GetLocalVarInt. The only thing is that local variables do not use the global.hps. It must be within the map' hps file itself.
EDIT:
You can declare new global variables in the maps .hps file. Although using a global.hps saves room.

This was pointed out by Adrianis.

"Veni, vidi, vici."
"I came, I saw, I conquered."
(This post was last modified: 03-30-2013, 12:06 PM by PutraenusAlivius.)
03-26-2013, 07:04 AM
Find
Adrianis Offline
Senior Member

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

Nice tutorial. It's worth noting that you can declare new global variables (that's using SetGlobalVar...etc) from any .hps map script, they don't all have to be in global.hps

03-26-2013, 01:11 PM
Find
PutraenusAlivius Offline
Posting Freak

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

(03-26-2013, 01:11 PM)Adrianis Wrote: Nice tutorial. It's worth noting that you can declare new global variables (that's using SetGlobalVar...etc) from any .hps map script, they don't all have to be in global.hps

Oh. But i'm using a global.hps so they don't clutter the .hps.

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-26-2013, 02:16 PM
Find
Adrianis Offline
Senior Member

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

(03-26-2013, 02:16 PM)JustAnotherPlayer Wrote:
(03-26-2013, 01:11 PM)Adrianis Wrote: Nice tutorial. It's worth noting that you can declare new global variables (that's using SetGlobalVar...etc) from any .hps map script, they don't all have to be in global.hps

Oh. But i'm using a global.hps so they don't clutter the .hps.

Of course - that's a good idea. Just wanted to add a note to the rest of it Smile

03-26-2013, 06:14 PM
Find
No Author Offline
Posting Freak

Posts: 962
Threads: 10
Joined: Jun 2012
Reputation: 13
#5
RE: Understanding on Global Variables and how to use them.

Does this script works with the "LocalVarInt" scripts ?

[Image: the-cabin-in-the-woods-masked-people.jpg]
03-27-2013, 02:28 PM
Find
PutraenusAlivius Offline
Posting Freak

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

(03-27-2013, 02:28 PM)No Author Wrote: Does this script works with the "LocalVarInt" scripts ?
LocalVarInt's are for Local Variables. Meaning that if you do something on one map, something else on that map happen.
GlobalVarInt's are for Global Variables. Meaning that if you do something on one map, something else happens on another one.

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-27-2013, 02:47 PM
Find
No Author Offline
Posting Freak

Posts: 962
Threads: 10
Joined: Jun 2012
Reputation: 13
#7
RE: Understanding on Global Variables and how to use them.

Took me awhile to understand that

[Image: the-cabin-in-the-woods-masked-people.jpg]
03-27-2013, 02:49 PM
Find
PutraenusAlivius Offline
Posting Freak

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

(03-27-2013, 02:49 PM)No Author Wrote: Took me awhile to understand that

1 min for me.

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-27-2013, 03:08 PM
Find
Wooderson Offline
Posting Freak

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

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.

[Image: luv.gif]
03-27-2013, 03:14 PM
Find
PutraenusAlivius Offline
Posting Freak

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

(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.

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-27-2013, 03:16 PM
Find




Users browsing this thread: 1 Guest(s)