playMaker

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

westingtyler

  • Full Member
  • ***
  • Posts: 186
    • 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"

loop


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


loop

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, manually...setting...every...single...game object variable.
« Last Edit: July 12, 2018, 07:18:19 AM by westingtyler »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: Set/Select Game Object FSM Variable By Name String?
« Reply #1 on: July 12, 2018, 11:11:36 AM »
Hi.
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)

westingtyler

  • Full Member
  • ***
  • Posts: 186
    • View Profile
    • My Oculus Rift + Touch VR Game Using Playmaker
Re: Set/Select Game Object FSM Variable By Name String?
« Reply #2 on: August 11, 2018, 11:24:27 AM »
Hello. I just want to clarify. Are you saying that we should ALWAYS grab and drag the game object or component into an FSM variable rather than using Find Game Object or Get Component, if at all possible? If so, that makes my life WAY simpler.

When you say Find Game Object is 'expensive' do you mean EXPENSIVE!!!! or "expensive" as in, not really expensive really, but not optimal?

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 777
    • View Profile
    • Fat Pug Studio
Re: Set/Select Game Object FSM Variable By Name String?
« Reply #3 on: August 11, 2018, 11:58:41 AM »
It's not a universal rule and it depends on how many game objects you have in the scene. But when making a game you'll usually end up with lots of objects and every one of them should be checked to see if the name matches the one you're looking for, hence the expensive part.

Dragging is shit too, always store references to your object since you'll probably have problems in build without them. Also, if something in the project gets screwed, you can easily end up with your dragged component fields empty.

terri

  • Sr. Member
  • ****
  • Posts: 371
    • View Profile
    • terrivellmann.tumblr.com
Re: Set/Select Game Object FSM Variable By Name String?
« Reply #4 on: August 12, 2018, 03:19:10 AM »
you could have the objects add themselves to an array or hashtable, that way you're not adding them manually

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: Set/Select Game Object FSM Variable By Name String?
« Reply #5 on: August 12, 2018, 05:30:46 AM »
Hi.
For placing a whole bunch of objects into an array or array list i made a tool which will be included in an asset i am working on (Tools for Playmaker)