Shared variable values between different worlds

Posted by Rdiniz on Thu 07 Jul 2016 03:13 AM — 7 posts, 29,124 views.

Brazil #0
When I want to play multiple sessions on the same mud, I just copy the .MCL into another new one and open 2 different sessions. That is working great.
I want some variables to be world(file) specific, which isn't happening like now. Lets say I have a (global?) variable named currentGainedXp, which incresas on each kill. I want somehow that session1 have its specific currentGainedXp value and session2 also have its specific currentGainedXp value. When I run with only one opened world, everything works great.
What is happening is that GetVariable("currentGainedXp") is returning a valid value from a random opened world.
How can I achieve that?


Thank you.
USA #1
Do the values of the variables need to be saved? Like if you close and re-open a world?

If not, then just don't use globals then they won't interfere with each other.

Otherwise, the quick solution would be to simply rename the global in the second world file.
Amended on Fri 08 Jul 2016 08:12 PM by Wuggly
Brazil #2
The vars don't need to be saved. I'll try to delete them under the Scripting -> Variables section and declare local to give it a try. I thought local vars would work only inside a function...
USA #3
Ah, I meant just don't use SetVariable and GetVariable.

They would still be globals, just within that world file unless you put local in front of it.

ie:
a = b is global
local a = b is local

Using SetVariable let's you use a variable between/across sessions from any plugin or world file using GetVariable to call it. So like the problem you're having is it's setting/updating the same variable from two sessions. So it's being added to twice.
Amended on Fri 08 Jul 2016 09:05 PM by Wuggly
Australia Forum Administrator #4
Quote:

What is happening is that GetVariable("currentGainedXp") is returning a valid value from a random opened world.


You can send data from one world to another by using the "world" functions. See: http://www.gammon.com.au/scripts/doc.php?general=world

However I'm not sure what you are trying to do. If you have multiple worlds open which is the "master" world?
Brazil #5
I want to have multiple alts playing in the same mud, at the same time. I'll be in one windows, which could me the 'main', and the others are playing by triggers. At some point, I want to check some variables from each alt, which in the case is each opened world, for example, how much xp each alt got.
I have all this info when playing one world only, but looks like I'm using global variables.
Australia Forum Administrator #6
You can use the "world" functions to find which worlds are open. See: http://www.gammon.com.au/scripts/doc.php?function=GetWorldById

You can these use the "world" identifier to do a "GetVariable" call to find the contents of a variable in that world.