Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Neikke on October 23, 2017, 08:46:37 PM

Title: How to reach for Script's function through action? [SOLVED]
Post by: Neikke on October 23, 2017, 08:46:37 PM
I have a C# script that kills a character on touch. So I would like to make an event where, If this script's particular Function/method is fired - Then do something. Is it possible?

Another example: I have a C# script that makes score to be counted during runtime. So I want to grab this function and multiply it by 2 or 3 in Playmaker. Is it possible?

Thanks in advance for any help and advice!
Title: Re: How to reach for Script's function through action?
Post by: Ofonna on October 24, 2017, 12:57:43 AM
to call a function from script, you can use the "call method action" you can also use invoke method, to use logic like you asked, you can use a public bool and when you're in the function set it to true, in playmaker you can test the bool by dragging the script into your fsm, when the bool is true fire an event.

in the second problem drag the script in and select the "get" option, get the float you want to multiply and then multiply it using the float multiply action.
Title: Re: How to reach for Script's function through action?
Post by: jeanfabre on October 24, 2017, 03:35:16 AM
Hi,

 don't forget that you can also create a custom action for this, if you have some basic coding ability, this is very easy.

 Bye,

 Jean
Title: Re: How to reach for Script's function through action?
Post by: Neikke on October 24, 2017, 05:39:37 AM
to call a function from script, you can use the "call method action" you can also use invoke method, to use logic like you asked, you can use a public bool and when you're in the function set it to true, in playmaker you can test the bool by dragging the script into your fsm, when the bool is true fire an event.

in the second problem drag the script in and select the "get" option, get the float you want to multiply and then multiply it using the float multiply action.

Sounds good! OK I'll try this. Thanks a lot!

Hi,

 don't forget that you can also create a custom action for this, if you have some basic coding ability, this is very easy.

 Bye,

 Jean

Unfortunately I'm not that good in coding (hopefully) just yet :) Thanks!
Title: Re: How to reach for Script's function through action?
Post by: Fat Pug Studio on October 24, 2017, 06:25:27 AM
I remember my not so proud beginnings when i see something like this :D Keep it up!
Title: Re: How to reach for Script's function through action?
Post by: Neikke on October 24, 2017, 06:31:24 AM
I remember my not so proud beginnings when i see something like this :D Keep it up!

:) hehe, yep I'll try my best ;)
Title: Re: How to reach for Script's function through action?
Post by: Neikke on October 26, 2017, 07:25:37 PM
to call a function from script, you can use the "call method action" you can also use invoke method, to use logic like you asked, you can use a public bool and when you're in the function set it to true, in playmaker you can test the bool by dragging the script into your fsm, when the bool is true fire an event.

in the second problem drag the script in and select the "get" option, get the float you want to multiply and then multiply it using the float multiply action.

Hi Carmichael! But how do I actually check if particular method in a script attached to my Player is true? Is there an action for this? Can you give me a bit more info on how to do it please? If I understand it correctly Invoke method and Call method actions are supposed to activate particular method from script rather than Check if it's true. Or am I missing something? Thanks in advance!
Title: Re: How to reach for Script's function through action?
Post by: Ofonna on October 27, 2017, 04:47:40 AM
to call a function from script, you can use the "call method action" you can also use invoke method, to use logic like you asked, you can use a public bool and when you're in the function set it to true, in playmaker you can test the bool by dragging the script into your fsm, when the bool is true fire an event.

in the second problem drag the script in and select the "get" option, get the float you want to multiply and then multiply it using the float multiply action.

Hi Carmichael! But how do I actually check if particular method in a script attached to my Player is true? Is there an action for this? Can you give me a bit more info on how to do it please? If I understand it correctly Invoke method and Call method actions are supposed to activate particular method from script rather than Check if it's true. Or am I missing something? Thanks in advance!

Hi, if i understand you correctly, your method returns a bool value and you want to test if it's true? you can simply store the result in a public variable and test it in the playmaker editor.

i made i simple setup where i press space to change the result of a method, i return the value to a public variable called "Isworking" and i get that in playmaker(by dragging my script it into the playmaker editor and selecting the get option).
now i can use the bool test action to test the function and mess with it or do whatever i want.

p.s Yes, invoke just invokes a method and call method simply calls it, so you can use the above system to test your function.
Title: Re: How to reach for Script's function through action?
Post by: Neikke on October 27, 2017, 05:25:22 AM
Thanks a lot for explaining it Carmichael! I see how to do it with bools! But what if I have something like this (attached) for a 'die' condition?

Title: Re: How to reach for Script's function through action?
Post by: Ofonna on October 27, 2017, 10:02:28 AM
Thanks a lot for explaining it Carmichael! I see how to do it with bools! But what if I have something like this (attached) for a 'die' condition?


you could also use a bool too, make a public bool called "IsDead", set it too false, then set it to true inside the die function, then grab it from playmaker the same way and test it,

p.s you could also send an event to playmaker when he dies instead of testing the bool every frame, it depends on your setup if that's what you prefer
Title: Re: How to reach for Script's function through action?
Post by: Neikke on October 27, 2017, 11:43:51 AM
you could also use a bool too, make a public bool called "IsDead", set it too false, then set it to true inside the die function, then grab it from playmaker the same way and test it

Uhmm something like this?

Code: [Select]
Public bool IsDead=false;
But how to set it to true inside die function? Sorry for stupid questions - I'm super noob in coding..

p.s you could also send an event to playmaker when he dies instead of testing the bool every frame, it depends on your setup if that's what you prefer

If you'd be kind to show me how to do it I'd be very very grateful.. if not - it's totally fine - I'll just go with some inefficient/performance heavy way probably..
Title: Re: How to reach for Script's function through action?
Post by: Ofonna on October 27, 2017, 12:55:30 PM
you could also use a bool too, make a public bool called "IsDead", set it too false, then set it to true inside the die function, then grab it from playmaker the same way and test it

Uhmm something like this?

Code: [Select]
Public bool IsDead=false;
But how to set it to true inside die function? Sorry for stupid questions - I'm super noob in coding..

p.s you could also send an event to playmaker when he dies instead of testing the bool every frame, it depends on your setup if that's what you prefer

If you'd be kind to show me how to do it I'd be very very grateful.. if not - it's totally fine - I'll just go with some inefficient/performance heavy way probably..

hi, there's no problem, you're going to learn with time :), i'm going to send you a script you can copy from with instructions on what to do
Title: Re: How to reach for Script's function through action?
Post by: Ofonna on October 27, 2017, 01:43:03 PM
hi, download the script and follow the instructions in the comment,
copy the code and add them to your script,
in the die function i created, just copy the send event action and add it to your die function.

before you do all that you can even test the script on an empty game object with an fsm so you can see it in aciton, press space to fire the event to playmakaer.

the image below shows the editor set up

p.s i just realised there are typos in the images, lol ignore the terrible english please
Title: Re: How to reach for Script's function through action? [SOLVED]
Post by: Neikke on October 29, 2017, 06:42:49 AM
hi, download the script and follow the instructions in the comment,
copy the code and add them to your script,
in the die function i created, just copy the send event action and add it to your die function.

before you do all that you can even test the script on an empty game object with an fsm so you can see it in aciton, press space to fire the event to playmakaer.

the image below shows the editor set up

p.s i just realised there are typos in the images, lol ignore the terrible english please


This is awesome! Now it's super clear for me and I finally understood how to make use of it even in other situations! Thank you so much for in-depth explanations and screenshots, Carmichael! It all works perfectly now and I don't have to check every frame for it! :)
Title: Re: How to reach for Script's function through action? [SOLVED]
Post by: Ofonna on October 29, 2017, 09:17:10 PM
hi, download the script and follow the instructions in the comment,
copy the code and add them to your script,
in the die function i created, just copy the send event action and add it to your die function.

before you do all that you can even test the script on an empty game object with an fsm so you can see it in aciton, press space to fire the event to playmakaer.

the image below shows the editor set up

p.s i just realised there are typos in the images, lol ignore the terrible english please


This is awesome! Now it's super clear for me and I finally understood how to make use of it even in other situations! Thank you so much for in-depth explanations and screenshots, Carmichael! It all works perfectly now and I don't have to check every frame for it! :)

i'm really glad it worked out!  ;D
Title: Re: How to reach for Script's function through action? [SOLVED]
Post by: jeanfabre on October 30, 2017, 03:19:39 AM
Hi,

 now that you are diving into the api of PlayMaker :)

 If you want more power, be sure to check out what the PlayMaker utils offers, I created over the years a lot of functions to communicate with PlayMaker easily, like sending an event to an Object without having to hold a ref to a PlayMakerFsm, just fire out of the blue very easily.

PlayMaker Utils is used in pretty much all the assets on the Ecosystem, like uGui, ArrayMaker, dataMaker, pathfinding, etc etc, so be sure to check it out.

I also created some specific classes that are meant to be used in your monobehaviours and exposes access to PlayMaker in the inspector, let me know if you need more info on this. basically you could be setting up the event to send all in the inspector without any hardcoding in the script itself.

 Bye,

 Jean