Author Topic: Variable Questions  (Read 1294 times)

So would this work?
You should really have a 'variable prefix' like how the default game uses Pref::Server::.

Something like $RPG::Gold[%client.bl_id]

So then the code would turn into this:

Code: [Select]
function GameConnection::saveVars(%client)
{
export("$RPG::*" @ %client.bl_id, "config/Vars/" @ %client.bl_id @ ".cs");
}
to load:
Code: [Select]
package autoLoad
{
function gameConnection::AutoAdminCheck(%client) //This is called once a client joins the server
{
if(isFile("config/Vars/" @ %client.bl_id @ ".cs"))
exec("config/Vars/" @ %client.bl_id @ ".cs");
else
%client.configureMedievalRpgSaves()();
return Parent::AutoAdminCheck(%client);
}
};
activatePackage(autoLoad);
and to remove data of a user who has left the server:
Code: [Select]
package autoSave
{
function GameConnection::onClientLeaveGame(%client)
{
%client.saveVars();
deleteVariables("$RPG::*" @ %client.bl_id);
return Parent::onClientLeaveGame(%client);
}
};
activatePackage(autosave);

Note the position of the *. This is a wildcard.

Thus, it saves/deletes anything that is $RPG::*[%client.bl_id]

If you want the bottom print to display all 4 of those variables, you'd need a tick function that calls this:

%client.bottomPrint("<color:4040f0>Health: <color:ffffff>" @ $RPG::Health[%client.bl_id] @ " <color:8080dd>MP: <color:ffffff>" @ $RPG::MP[%client.bl_id] @ " <color:c0c0c0>Class: <color:ffffff>" @ $RPG::Class[%client.bl_id] @ " <color:9c6963>Gold: <color:ffffff>" @ $RPG::Gold[%client.bl_id],10);

(I didn't know if health and MP were current or max, you'd have to clarify on that.

Is it possible to make a variable appear as a word?

Variables can be words.


So I would use
Code: [Select]
$Var[%client.bl_id]to modify a var?