playMaker

Author Topic: How to reach for Script's function through action? [SOLVED]  (Read 6825 times)

Neikke

  • Full Member
  • ***
  • Posts: 134
How to reach for Script's function through action? [SOLVED]
« 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!
« Last Edit: October 29, 2017, 06:44:23 AM by Neikke »

Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: How to reach for Script's function through action?
« Reply #1 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to reach for Script's function through action?
« Reply #2 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

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to reach for Script's function through action?
« Reply #3 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!

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to reach for Script's function through action?
« Reply #4 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!
Available for Playmaker work

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to reach for Script's function through action?
« Reply #5 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 ;)

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to reach for Script's function through action?
« Reply #6 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!

Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: How to reach for Script's function through action?
« Reply #7 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.
« Last Edit: October 27, 2017, 04:53:20 AM by Carmichael »

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to reach for Script's function through action?
« Reply #8 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?


Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: How to reach for Script's function through action?
« Reply #9 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

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to reach for Script's function through action?
« Reply #10 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..
« Last Edit: October 27, 2017, 11:47:47 AM by Neikke »

Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: How to reach for Script's function through action?
« Reply #11 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

Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: How to reach for Script's function through action?
« Reply #12 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
« Last Edit: October 27, 2017, 01:52:02 PM by Carmichael »

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to reach for Script's function through action? [SOLVED]
« Reply #13 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! :)

Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: How to reach for Script's function through action? [SOLVED]
« Reply #14 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