Jump to content

Can I set variables global to The World?


Recommended Posts

Is there a way I can set a variable bound to the world? I need items from different characters to be able to modify a variable, lets say one player uses the item, and the variable for the world increments from 0 to 1, and if another player uses the item, it goes from 1 to 2.

Sorry for the short and undetailed question I'm extremely tired after 8 hours of work + another 6 of amateur development.

Edited by TheSkylarr
Link to comment
Share on other sites

Yeah, you can do this

Like, lets suppose you have a variable "var" that initially is 0

You can set
TheWorld.var=0

and in the item you can write
TheWorld.var=TheWorld.var+1

The only problem with this is the initial declaration, that can be done this way in modmain

AddPrefabPostInit("world",function(inst)
    inst.var=0
end)
 

Link to comment
Share on other sites

19 minutes ago, Gleenus said:

Yeah, you can do this

Like, lets suppose you have a variable "var" that initially is 0

You can set
TheWorld.var=0

and in the item you can write
TheWorld.var=TheWorld.var+1

The only problem with this is the initial declaration, that can be done this way in modmain

AddPrefabPostInit("world",function(inst)
    inst.var=0
end)
 

This works almost perfect for what I need to do, thank you! I guess since it's declared in modmain though, I need to make sure the ability can't be already being used when the world is saved.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...