Author Topic: Set/Select Game Object FSM Variable By Name String?  (Read 57 times)


  • Full Member
  • ***
  • Posts: 159
    • View Profile
    • My Oculus Rift + Touch VR Game Using Playmaker
Set/Select Game Object FSM Variable By Name String?
« on: July 12, 2018, 06:14:32 AM »
I have an inventory grid with 40 game objects acting as slots. they are named inv_01....40 etc.

I want an fsm to get these and store them in that fsm as their respectively named game objects.

I'd like to be able to build a string with an int, and loop it until reaching 40, each time finding that named game object and storing it in its fsm game object variable. but I don't want 40 separate states with a uniqueley, personally, individually set game object destination.

The problem is I can't set a game object using its string name. I have to manually create 40 fsm game object variables, name them accordingly (that's all fine), then have a string switch with 40 outputs, each going into an event that sets THAT game object to THAT pre-designated variable from a dropdown list.

what I want is:

find game object [built string "inv_X"]
and save to fsm game object [built string "inv_X"]

in other words, saving to that game object based on the string chosen. kind of like a "for each, save to its" thing. even if i had to create and name the fsm game object variables ahead of time, i'd like to be able to call and set them by a string. because currently it's like this:

find game object [built string "inv_X"]
int switch =  if 1, send to
store it in 'GAMEOBJECT_01"


find game object [built string "inv_X+1"]
int switch =  if 2, send to
store it in 'GAMEOBJECT_02"


find game object [built string "inv_X+2"]
int switch =  if 3, send to
store it in 'GAMEOBJECT_03"

or what i've done before, which is a single state with 40 find game object actions, each with an incremented game object variable from the dropdown list.

so I need 40 states instead of 1 that just says "get it of name X, store it in gameobject X with same name." then looping that single state up to a max int.

does this make sense? is this possible? it would save a crapload of time to be able to use a string to set a similarly named game object variable. rather than manual dropdown selecting the game object for 40 different states.

Here's a fake picture of the action that would save me one billion years if it really existed. A Set version, and a Find version is what I wish I had.

And the second picture is a faked version of what I'm trying to simplify. if I could just save built the needed string, then use it in those places, in each loop, my life would be great. I could just Get Last Event, and use that string, then loop it. Unless there's a better way?

As it is I have to do the garbage in the third image, object variable.
« Last Edit: July 12, 2018, 07:18:19 AM by westingtyler »


  • Administrator
  • Hero Member
  • *****
  • Posts: 3181
    • View Profile
    • jinxtergames
Re: Set/Select Game Object FSM Variable By Name String?
« Reply #1 on: July 12, 2018, 11:11:36 AM »
I am not sure what exactly what you mean so bare with me.

But Find Game Object is 'expensive' to use.

Place you "slots" into an array.

Then use 'Array Get Next' to loop thru them and also get the index.

inv_01 will be index 0, inv_02 will be index 1 and so on.

You can then use 'get name' on the selected gameobject when needed and do with it what you need to do and then loop back to array get next.

If you need to make a string from int do an 'int add' 1 to the index to have the same number as the object.

If you do not need to loop thru them but something similar as finding it you can use 'Array Get' and lets say you needed inv_22 then you would need to look for it on index 21 (22 - 1)