Blockland Forums > Modification Help

Variable Questions

Pages: << < (2/4) > >>

jes00:

I'm guessing you replace %var with the variable?
And for saving I replace $var with the variable?

Headcrab Zombie:

Yes

Chrono:

There are many ways to save and load variables.

% is for a temporary variable that gets discarded after whatever used it is finished with it. Such as:
-A console entry will discard it after evaluating everything in the entry.
-A function will discard it after it's completed.
-An executed file will discard it after the file is finished executing.

$ is for a permanent variable which will remain even after the method is complete.

So doing:


--- Code: ---function test()
{
%test = 5;
}

test();
echo(%test);
--- End code ---

Will echo blank, however, doing


--- Code: ---function test()
{
$test = 5;
}

test();
echo($test);
--- End code ---
will echo 5.


As for saving them, if you're using these kinds of variables, it's a good idea to store them with a keyword at the beginning of it, like:

$RPG::YOURVARNAMEHERE

such as

$RPG::Time


You would save all variables beginning with $RPG:: into a single file like this:

export("$RPG::*","config/server/my_rpg.cs",0);

and to load it, use exec

exec("config/server/my_rpg.cs");


Another thing to know is 'arrays' or whatever they're actually called. With this you can store variables and have a conditional reference to it. Such as:

$RPG::Gold[%client.bl_id]+=5;

This will give %client 5 gold and store it based on ID. (which only show up on client objects [or called GameConnections])
Saving and loading would work the same way.



There are other ways for storing, saving, and loading variables. But this is probably the simplist way. Not sure if it would be good on RAM after several different users have accessed your server, as this loads everyone's data whether or not they're on the server.

infiniteLoop:

I'm just wondering why you all are writing the same thing over and over and not just linking him to a tutorial. I think ibans tutorial explained everything.

jes00:

So how would I

* Save and load the players data only if they join the server.
* Display the players variable.

Pages: << < (2/4) > >>

Go to full version