[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Shared variable values between different worlds

Shared variable values between different worlds

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Rdiniz   Brazil  (21 posts)  [Biography] bio
Date Thu 07 Jul 2016 03:13 AM (UTC)
Message
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.
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #1 on Fri 08 Jul 2016 08:11 PM (UTC)

Amended on Fri 08 Jul 2016 08:12 PM (UTC) by Wuggly

Message
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.
[Go to top] top

Posted by Rdiniz   Brazil  (21 posts)  [Biography] bio
Date Reply #2 on Fri 08 Jul 2016 08:26 PM (UTC)
Message
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...
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #3 on Fri 08 Jul 2016 08:53 PM (UTC)

Amended on Fri 08 Jul 2016 09:05 PM (UTC) by Wuggly

Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,986 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sat 09 Jul 2016 06:25 AM (UTC)
Message
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?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Rdiniz   Brazil  (21 posts)  [Biography] bio
Date Reply #5 on Sat 09 Jul 2016 12:48 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,986 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sun 10 Jul 2016 06:27 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


18,354 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]