playMaker

Author Topic: Best way to use set / get event properties?  (Read 2077 times)

Snowbird

  • Playmaker Newbie
  • *
  • Posts: 25
Best way to use set / get event properties?
« on: August 11, 2019, 10:46:22 AM »
Say I have a bunch of enemies (that are prefabs, therefore the same, minus the (#) ), and have 'set event properties' attached to them for various reasons, for example: Damage text when they get hit, variables they send to the character, like experience yield, knockback multipliers, etc.

Everything seems fine about this, until multiple of these prefabs need to send an event simultaneously. Like if an attack damages 4 of them at once, sometimes a value of 0 gets sent.  Because of this, I have taken to never using 'set / get event properties', but now I am stuck using 'get fsm variable', which works just fine, but doesn't seem to be the correct way to do things.

I am sure there are multiple simple solutions that I am just not thinking of atm. Would it be something like getting the exact name of the prefab, making it a string, and placing that as the value of 'key' in both the prefab and the character? Seems like a bit much (like why wouldn't I just grab the variable if I'm doing all that), but would probably work.. I think. Is there something simple I'm missing? I will have to do this in multiple locations of what I am working on, likely hundreds of different times, and my current solution of "get fsm variable" seems okay but doesn't seem like proper 'code'.

Thanks for any help!
« Last Edit: August 11, 2019, 10:53:18 AM by Snowbird »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Best way to use set / get event properties?
« Reply #1 on: August 11, 2019, 07:48:14 PM »
Hi.
Possibly it did not send a value of 0, but its not registered because it happens in the same frame.

For multiple damage you can use an array or more preferably Array list (array maker Ecosystem)

enemy damage : array list add (x damage value)

player : check array length every frame, and when 1 or larger : array list get (index 0) then deduct damage, then array list remove at (index 0) then go back to check array length.

But Get/set fsm variables i use a lot on enemies (when hit by player).

Usually i have a fsm called Data on all enemies, weapons, player so that its easy to know where to get the data.

I also use get /set fsm action on the same object to get/set variables on the 'Data' fsm.
The current project i am working on has now around 1000 get/set fsm actions
and that will probably double by the time the game is ready (player/enemies have several stats)

Snowbird

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Best way to use set / get event properties?
« Reply #2 on: August 12, 2019, 02:20:42 PM »
Would you care to explain the array list in a little more depth?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Best way to use set / get event properties?
« Reply #3 on: August 13, 2019, 06:31:50 AM »
Hi.

Here you can find some tutorial videos about array list (arraymaker) : https://forums.tigsource.com/index.php?topic=46995.0

And here is a setup to handle damage.



So any damage to receive you should use 'array list add' and Reference the 'Damage List'

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 773
Re: Best way to use set / get event properties?
« Reply #4 on: August 18, 2019, 03:23:46 PM »
Best way to handle set / get event property?
Code the action.  :P
You may wonder if this is hard. At first yes, a bit, but just pick an already existing action that does something like, say, set a float value, and see how it works (double click on it and launch the code editor associated to Unity, either Mono or the new Microsoft tool). The c# (C Sharp) syntax is relatively simple enough to understand for simple functions.
You'll need the Unity API scripting documentation available on the website.
Whereas you can set values in Unity by typing
Code: [Select]
myfloat = 2f;in Playmaker actions you need to use the name of your variable and add
Code: [Select]
.Valuebehind it so it looks like this:
Code: [Select]
myfloat.Value = 2f;= sets the value of a variable.
It's literally written with the following logic:
"My variable's value is now equal to [value]."
It's different from verifying if a variable has a given value (usually inside 'if then' etc. nested sections inside a script). For verification, the syntax would require using == (is it equal to?).
Taking a look at the beginner level video tutorials on Unity's website will give you the basics you need to know.
If you take time going through this, you'll save yourself needless anxiety you'd feel by wondering if the program will work flawlessly with those get/Set actions.

As for arrays, it's really up to your preferences.

You can use an Array List (proxy) component on a game object or use the Array type variable inside the FSM (create an Array var and then decide what it is going to store).
A thing not obvious to users of Array Lists is that although you can preset a given number of items, they will all be of the same type. BUT it does not mean you cannot add items of other types too. When would such a case occur?
Well, when for example you use a short Array List to store half a dozen variables of different types, relative to an object, an element of your scene, perhaps one you'd instantiate too.
Say a character/player name, sprite for avatar, some ints and floats regarding attributes, etc.
However you will have to add those elements through "code" because you can't do that manually, since PM will only allow you to define a single type of variables for all the items you'd preset in your Array List.