View unanswered posts | View active topics It is currently Fri Nov 01, 2024 1:32 am



Reply to topic  [ 4 posts ] 
 Setting a global variable to nil when activity changes 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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?


Thu Dec 14, 2017 3:48 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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.


Thu Dec 14, 2017 9:17 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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


Fri Dec 15, 2017 3:11 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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 :)


Fri Dec 15, 2017 6:39 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.028s | 15 Queries | GZIP : Off ]