PlayMaker News > General Discussion

Is it possible to create new variables at runtime?

(1/2) > >>

craigz:
Was curious whether it was possible to create new variables on an FSM at runtime :)

-craigz

jeanfabre:
Hi,

 yes, the api should allow for this, but it doesn't make sense since none of the fsm would be wired to actually use it, can you explain your use case?

 bye,

 Jean

craigz:
Hi Jean!

I'm SO sorry for the crazy late response, notifications for this thread were off for me I guess? xD but this is still something that I would find super useful! :D

The main use case would primarily be for manager objects, where instead of interacting with a component to manage things (like using a hash table to keep track of how many units there are of a certain type and recording their stats) you could instead create the variables for those units on scene loading, and so long as you had a deliberate naming scheme, interacting with an FSM would be infinitely easier than a component :)

I know for me personally I usually end up having a lot of my data loaded in through hash tables, but it gets pretty messy to manage/interact with. Especially at run time, when you're getting and setting keys constantly.

For instance, say you have a 'FSM.UnitManager' and its whole goal is to keep track of unit stats in a level. Like how many kills, deaths, etc each type of unit has in a scene. You could create all the variables needed for each unit, and then since the game objects themselves have names, you can automate using a key system to interact with that data, so then all you'd have to do is use the regular actions like 'Subtract FSM Int', and then use the key (which would come from a build string) for the variable name.

This is my current setup though!

HashTableProxy
----------------
blue_archer_countStart
blue_archer_countEnd
blue_archer_countCurrent
blue_archer_kills
blue_archer_deaths
blue_crossbowman_countStart
blue_crossbowman_countEnd
blue_crossbowman_countCurrent
blue_crossbowman_kills
blue_crossbowman_deaths
red_bandit_countStart
red_bandit_countEnd
red_bandit_countCurrent
red_bandit_kills
red_bandit_deaths

And while my current setup *does* work, every time I need to set something on the hash table, I have to check if the key exists, and if it goes, get the Int, then add to the Int, then set the Int. It just seems like a lot of leg work for something that an FSM could handle easily if it could just create variables at runtime xD especially because I'm generating from a library of units created at runtime, not a bunch of prefabs (because they all share the same basic setup).

Let me know what you think, I know my example might sound niche, but I know you see the value of creating variables at runtime in general :P

-craigz

djaydino:
Hi.
You might want to look into using xml or json.

and get datamaker to read/write the xml file.

Here are some video's that can help you get started with datamaker :

//www.youtube.com/watch?v=gqRwEPGjWpk
//www.youtube.com/watch?v=eB_E4embTvw

craigz:
Hey djaydino!

I've looked into both xml and json and know the datamaker extension. If you're updating those constantly during a game (say for runtime stats etc) performance actually takes pretty big hit.

Thats why (I was hoping?) I guess past initializing a manager object and creating variables at the start of a scene, it would be more performant? :)

-craigz

Navigation

[0] Message Index

[#] Next page

Go to full version