PlayMaker Help & Tips > PlayMaker Help

How to set up Int Compare to use a variable from another FSM? [Solved]

(1/1)

Gevarre:
Sorry for all the questions, but this really is a different way of working for me and I'm still getting used to it.

In my scene, I've got a pickup manager that's spawning a pickup with network instatiate and sending it an integer value. The pickup is then supposed to read that integer value and activate various components accordingly. The trouble is that it always ends up being false no matter what I do. I'm guessing I'm doing something wrong since I've tried this with Integers, strings, and game objects and it always is the same. I'm not using any global variables on this, if that makes any difference.

The first image, labeled "SetInt", is the pickup manager. It is generating the number 5 and storing it in the variable "testActivated". It is then network Instantiating the prefab "Pickup" and saving it in the variable "spawnedPickup". After that it uses Set FSM Int to set the variable "testActivated" on spawnedPickup. So far, so good. You can see all the values there.

The second image, labeled "IntCompare", is the pickup. It just uses Int Compare to read the variable "testInt" (which is on the pickup). You can see that it reads the value of "5", but when it compares it to "integer 2", which is set to "1", it returns that it is Less Than, which obviously it isn't.

I'm guessing it's not actually seeing that "5" as an integer, but I have no idea how to fix it.

Any ideas?

jeanfabre:
Hi,

 you don't give a Fsm name when you use "set Fsm Int" that might be the reason why it never gets set.

 in that field, you can select the existing ones, make sure the fsm name matches, else it will not work.

bye,

 Jean

Gevarre:
The FSM name is actually optional (you can see that in the tooltip if you hover over the field). If none is specified, Playmaker will just grab the first FSM it finds on the target object. Just to be sure though, I did try it with the name in there, and it made no difference.

If you look closely at the images, you can see in the debug fields that the int is actually being passed:

* Random Int generates a 5.
* Network Instantiate spawns the object called "Pickup(Clone)" at the spawnpoint "Pickupspawn".
* Set Fsm Int does "Set Value" of 5 on the Game Object "Pickup(Clone)
* Int Compare gets the value of 5 (note the debug field under "integer 1" in the second screenshot
The value of the variable "testInt" is set to 0 by default, so if it wasn't receiving the number, there would be no way it could be changed to 5.

So even though I can see right there that "integer 1" has a value of 5 and "integer 2" has a value of 1, it's returning a result of "Less Than", which can't be. I've run it multiple times with different values, and even if Integer 1 and Integer 2 match, it always returns with the result of "Less Than". If the Less Than event field is left blank, then nothing happens at all. The FSM just sits in this state.

To try to debug, I went back and created everything step-by-step, adding one thing at a time and testing. If I do the same setup and use "Create Object" instead of "Network Instantiate", it works perfectly. Once the Network Instantiate action is added, it stops working, which is weird, because with the above example, you can see that the value is actually getting passed, it's just not evaluating correctly.

Since the Int Compare action will only accept integers, I would guess that Set Fsm Int is actually sending the integer correctly, otherwise the testInt variable wouldn't allow it to be stored there and Int Compare wouldn't accept it. I'm also guessing that if there was some kind of type mismatch, that the value of "Integer 1" in the Int Compare action would be either blank or 0 or that it would complain.

I hate to cry "code bug!" every time something doesn't work for me because I do realize I'm pretty new with playmaker, but I'm stumped as to what else this could be. I've also looked at the code for the actions and with my limited knowledge, I didn't see anything obviously wrong with anything, but I'm definitely not a coder. I guess the next step is for me to "hard code" this example with C# scripts instead of using Playmaker and see if I can get it to work. Maybe it just a bug with Unity's networking and nothing to do with Playmaker at all.

Let me know if you have any other thoughts or suggestions and I'll try to test them out.

Lane:
If this is immediately at runtime then on awake the recipient FSM may be checking the Integer before it is randomized and sent, which would mean that it fails, then gets the update and shows you that in the fail state debug.

In other words, its waking up, checking the int and failing it before the other FSM can randomize it and send it.

Gevarre:
Good call. That fixed it :)

I would never have thought to check that. Adding a wait action before doing the compare makes it work perfectly.

Thanks for the help.

Navigation

[0] Message Index

Go to full version