Data Realms Fan Forums
http://forums.datarealms.com/

Setting a global variable to nil when activity changes
http://forums.datarealms.com/viewtopic.php?f=73&t=46230
Page 1 of 1

Author:  Asklar [ Thu Dec 14, 2017 3:48 am ]
Post subject:  Setting a global variable to nil when activity changes

I'm making a mod (not a scene) that currently relies on using global tables as a mean to save information from the scripts of different objects. Because of this, I need a way to delete this table whenever the activity changes so that I have a new, empty table to work with, instead of accidentally using old data.

I tried putting ActivityMan:GetActivity().ActivityState == OVER as a conditon in the update function but after I beat the activity (game over screen and all) and start another one the table was still there (though this solution isn't exactly optimal anyways because I don't think you can detect if the game has been reset or just quit either). I also tried in the create function to check the state of the game and delete the table if the state is started, starting, editting, etc., but there's no guarantees that the item will be bought/placed in those stages to reset the table. I clearly can't do it with running.

The obvious solution I've come up with is using another item that when bought/placed deletes the table (or just typing it in the console), but that's not very user friendly.

What other thing could I try to do?

Author:  Bad Boy [ Thu Dec 14, 2017 9:17 pm ]
Post subject:  Re: Setting a global variable to nil when activity changes

The answer to this kind of depends on how you're doing this but one easy solution is to attach the script to something that can't be killed normally (i.e. not hittable), then setup the table on create and clear it on destroy, since the latter will only trigger on the end/restart of the scene. You'll probably want the create to check to be sure the table doesn't exist before setting it up, in case multiple of the scripted object get made somehow. Or make it so only one of the object can exist by adding a check at the start of create to delete any other instances of itself.
Alternatively, you might be able to store some combo of activity classname and activity scenename, though that might not handle restarts too well.

Coincidentally, the former is basically what I do for movators which I've been recently working on, so I'm pretty sure it works well.

Author:  Asklar [ Fri Dec 15, 2017 3:11 am ]
Post subject:  Re: Setting a global variable to nil when activity changes

I had no idea the destroy function was ran when a scene restarted/was over/etc.! Thanks a lot, I followed what you said and made the script deactivate if another object of the same type was created, and in the destroy function made it delete the global values, which worked out perfectly.

Once again thanks! :D

Author:  Bad Boy [ Fri Dec 15, 2017 6:39 am ]
Post subject:  Re: Setting a global variable to nil when activity changes

Cheers man, nice to see another fairly old hat trying cc modding again around the same time I am. Have fun with whatever you're working on :)

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/