The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



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


Messages In This Thread
Understanding on Global Variables and how to use them. - by PutraenusAlivius - 03-26-2013, 07:04 AM



Users browsing this thread: 3 Guest(s)