playMaker

Author Topic: Public FSM Events and FSM variables in scripts?  (Read 6845 times)

KJIB

  • Playmaker Newbie
  • *
  • Posts: 20
Public FSM Events and FSM variables in scripts?
« on: October 12, 2012, 08:02:34 AM »
I can use a string to send a given named (in a string) event but I am trying to set up something that is more reliable than a string to reference FSM stuff.

Why: Because if I, (or someone else), change the event name in Playmaker I really want that name to change in my scripts public inspector area too or I end up with having to find why my app is broken (i.e. because the name of the event I'm using has changed but the instance of the script didn't get its version of the name updated). Same for FSM variables. Also, I'm the only coder on our team so, if it breaks, it's going to eat my time as (most of the time) no-one else knows how to work out what the problem is.

Ideally I'd like the user to be able to drag the FSM to my script AND to then be able to let the user select from the editor events/variables from that FSM to define a reference to it for me to use in the script. (e.g. is there a way for me to get a reference to the name string in Playmaker or something so the string is only held in one place anyway? etc.). If I can't reference the specific FSM then globals would be better than nothing.

At the moment I might have something like this to let the user setup a script that needs to send Playmaker events or do something with a Playmaker variable:
Code: [Select]
public PlaymakerFsm targetFsm;
public string FsmEventNameForBadData;
public string FsmBoolVarNameForResult;

I did try a test using an FsmEvent and setting the name in that structure but this does not reference a specific FSM and when I edited the event name in Playmaker it does not change the name in the instance (as expected since Playmaker presumably has to find it somehow).

How can I reference things in a way so when I edit event/variable names in Playmaker it updates in my script instance references too?

Thanks  :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Public FSM Events and FSM variables in scripts?
« Reply #1 on: October 16, 2012, 05:38:57 AM »
Hi,

 I am not really aware of any such referencing. I would be incline to think that it is possible, but currently, for event and fsm variables, it's all about hardcoded string referencing for me. For the FSM component itself, that's fine, you store the Fsm component itself and you don't have to worry at all about the fsm name.

bye,

 Jean

KJIB

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Public FSM Events and FSM variables in scripts?
« Reply #2 on: October 16, 2012, 06:51:13 AM »
Yes, I've found no problem with the FSM object but have already had a case where an event name got changed in an FSM which broke the project (i.e. with the event being named in a string for script use). Having a seemless mechanism where I can drop a Playmaker event (or variable) into an inspector slot like I can with an FSM would be nice.

Has anyone come up with a good solution to this (other than storing a string for the name of the event/variable)? Something along the lines of getting a reference to the name of the event/variable (so when someone renames things I don't care as I will point to the same string Playmaker holds... a bit like a pointer or reference in C or C++ ).


DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: Public FSM Events and FSM variables in scripts?
« Reply #3 on: October 24, 2012, 11:11:59 AM »
Maybe if you save the reference to the FsmEvent object itself, through Fsm.FsmEvents property. The only thing is that you must know the index of your desired event to look for it on that array (I don't know yet how to look for an event, given a name or string). Another issue is that, as fas as I have seen, if you change your event name, it'll change its index. It  might work if you change the  name in runtime.

By the other hand, your string property could be public, and you just have to reassign that on the inspector.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

KJIB

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Public FSM Events and FSM variables in scripts?
« Reply #4 on: October 25, 2012, 04:00:33 AM »
Quote
Maybe if you save the reference to the FsmEvent object itself, through Fsm.FsmEvents property. The only thing is that you must know the index of your desired event to look for it on that array (I don't know yet how to look for an event, given a name or string). Another issue is that, as fas as I have seen, if you change your event name, it'll change its index. It  might work if you change the  name in runtime.
Hmmm, sounds like it leaves me with the same potential issue. I also need to be able to let the person changing an FSM change events used elsewhere so they need to refer to the name of the event, (a number or anything else vague defeats the essence of an easy to use system).

Quote
By the other hand, your string property could be public, and you just have to reassign that on the inspector.
This is what I do now but I have to rely on the person changing the event name to change it everywhere and as they see a dialog with Playmaker apparently doing it they may not think to check.

For larger projects, something like this really could do with a solution... Anyone?  ???

DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: Public FSM Events and FSM variables in scripts?
« Reply #5 on: October 25, 2012, 11:09:38 AM »
Try the Fsm.GetEvent(string evName) function in the script. From the PlayMakerFSM object, get the Fsm object, and then you can use that function I said before, and the parameter would be the name of the event you might want to get.

Hope that helps.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

KJIB

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Public FSM Events and FSM variables in scripts?
« Reply #6 on: October 25, 2012, 11:22:18 AM »
Your input is welcome, thank you  :), but the solution you mention would still leave me with an unrecognised event name if someone renames it (i.e. it still won't rename in my script - the script will try to find the event and then either get null for the event or the wrong event). I need to be able to kind of register my use of an event with Playmaker so it "knows" I want my event name updating when it's name for it changes (i.e. so that same thing happens in a script as happens in an FSM when you rename events - all references to the event get updated not just the FSM ones).


DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: Public FSM Events and FSM variables in scripts?
« Reply #7 on: October 25, 2012, 11:41:18 AM »
The only thing I can think to solve that, for now, is that your event name (which I suppose would change in authoring time AND in runtime) is stored in a variable (I suppose a global would do the trick), and, whenever the event name changes or the FSM starts, you store the new value in a variable and your script should only ask for that variable's value. I'd like to know how exactly do you expect that event name to change, why (I mean, what sort of input would cause that event name to change), because it could be an important feature of whatever you're implementing, so I can think on a better solution, since I feel I'm having a vague understanding of your issue and your needs.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

KJIB

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Public FSM Events and FSM variables in scripts?
« Reply #8 on: October 25, 2012, 12:12:20 PM »
The event names (and anything else) get changed because other people are working the project & sometimes feel a change of name is needed. This is where it can go wrong, particularly if they do not notice & check it in etc. Doubly so because Playmaker says that it's changing all references for you so folks assume it's OK to keep on doing it. Little do they know... :'(

DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: Public FSM Events and FSM variables in scripts?
« Reply #9 on: October 25, 2012, 12:32:37 PM »
So, it's more like a management problem. You, or they, or whoever takes place in a proyect, don't change something like that because you feel like doing it, or you shouldn't, I fear.

If I was you, I'd make a naming scheme and share it to the whole team, so everyone accept that, because that checking you want to do is entirely for develop purposes and, as I understand, it shouldn't change anything in your implementation's logic. It'd be better to spend a little more time in design than thinking how to implement something you shouldn't need.

Given that scenario, anything can happen, and thus any action would be futile, since that thing you want is not featured by Playmaker. It seems that is not enough to store events as variables, although you could do it, but then, which variable would refer to which event that defines a specific transition? But, if they change an event name, your only problem is if you hardcode the names and use them for any logic, since Playmaker will change that name wherever it's used. The best I can say now is... Avoid hardcoding event names, or if you need to do it, agree with your team a naming scheme.

Greetings.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

KJIB

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Public FSM Events and FSM variables in scripts?
« Reply #10 on: October 26, 2012, 03:52:28 AM »
Yes, I agreee. In an ideal world we'd be able to agree a naming scheme & it would all work but needing to do that is a sticking plaster over something that I think we could do better. People sometimes think they're being helpful or they try to add stuff etc.

I'd still like to see a mechanism in place for this. There is obviously something in Playmaker already, can we have access to it please?