Changing Playmaker Globals within a converstaion?

Announcements, support questions, and discussion for the Dialogue System.
Taka
Posts: 12
Joined: Sun Jul 29, 2018 3:29 pm

Changing Playmaker Globals within a converstaion?

Post by Taka »

Hi, I've just bought Dialogue System today and am fairly new to Unity as well, so excuse me if this seems like a dumb question but:
How can I Set a Playmaker global Int from within a conversation? For example: Add "xAmount" to "FsmInt".

My game stats are stored as playmaker global variables and would like to be able to edit them up quest completion.
I've tried making a GameObject containing an FSM that adds to an Int, then activating it in the Events section, but that didn't seem to work. And I'm not yet proficient enough at C# to figure out how to script it.

Any advice would be welcome!
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Tony Li »

Hi,

Thanks for buying the Dialogue System!

First import the PlayMaker Support package. This will add a number PlayMaker Lua functions that you can use in nodes' Script fields.

For example, say the NPC heals the player to 100 Health. You've defined an int global variable named "Health". Set the node to:
  • Dialogue Text: "Be healed!"
  • Script: SetFsmInt("Health", 100)
Taka
Posts: 12
Joined: Sun Jul 29, 2018 3:29 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Taka »

That's great, thank you.

And if I wanted to add say 50 Health to my total would it be something like:

SetFsmInt("Health", +50)

or is that wrong? Again, sorry for the newbie questions.
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Tony Li »

No worries; happy to help! Use this:

Code: Select all

SetFsmInt("Health", GetFsmInt("Health") + 50))
In English, this sets Health to the current value of Health plus 50.
Taka
Posts: 12
Joined: Sun Jul 29, 2018 3:29 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Taka »

Awesome, thank you very much for the help!
Taka
Posts: 12
Joined: Sun Jul 29, 2018 3:29 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Taka »

I'm sorry, but I can't seem to get this code working.
I've tried several different variations of what you gave me but none of them work:

SetFsmInt("Money", GetFsmInt("Money") + 50))' threw exception 'Code has syntax errors:

SetFsmInt("Money", GetFsmInt("Money") + 50)' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'

SetFsmInt(Money, GetFsmInt(Money) + 50)' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'


I have installed the Playmaker support package. I had a look in the Actions folder that it created, but I couldn't see a script for "GetFsmInt" or "SetFsmInt". Is that intentional or am I missing them?
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Tony Li »

Sorry, I pasted the link to the documentation and then totally forgot to point out this important line:

"To make PlayMaker-specific Lua functions available, add the component Dialogue System PlayMaker Lua to your Dialogue Manager."

If you add that component to your Dialogue Manager, you should be good to go.
Taka
Posts: 12
Joined: Sun Jul 29, 2018 3:29 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Taka »

That's sorted it, thanks.
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Playmaker Globals within a converstaion?

Post by Tony Li »

Happy to help. Glad it's working now.
Jajamave
Posts: 2
Joined: Tue Nov 06, 2018 9:03 am

Re: Changing Playmaker Globals within a converstaion?

Post by Jajamave »

Hi I am also using dialogue systems with playmaker
I'm using lua to update playmaker global variables and have the lua script on my dialogue manager (just as you described) and it worked fine so far.
but when I switch between scenes the connection to the playmake Globals seems to fail and i get the same errors as if i didn't use the 'dialogue system playmaker lua' script:

Lua code 'SetFsmBool('HasLamp', true)' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'

can you please help me?

(I recently added the 'easy safe' plugin to my project -might that be a problem?)
Post Reply