playMaker

Author Topic: Calling Public Functions with multiple variables  (Read 2611 times)

Clockwork Wolf

  • Playmaker Newbie
  • *
  • Posts: 7
Calling Public Functions with multiple variables
« on: September 02, 2013, 10:32:21 PM »
Hello!
I am trying to call the public function, damage() in the script below, however SendMessage action takes only one parameter, and I think InvokeMethod action does not even allow parameters (NOTE: PM says it is fine, but errors in the unity console)?

Code: [Select]
using UnityEngine;
using System.Collections;

public class PAClass : MonoBehaviour {

public int HP = 100;
public float multDark = 0.75f;
public float multLight = 0.25f;



public void damage(int damageDark, int damageLight)
{
float currentDamage = ((float)damageDark * multDark) + ((float)damageLight * multLight);
HP -= (int)Mathf.Floor(currentDamage);

print ("Damaged by: " + currentDamage);

if (HP <= 0)
{
print ("I am dead!");
Destroy(this.gameObject);

}

}

public void testDamage(int damage)
{
HP -= damage;
}

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
}


There is another function, testDamage in the code that works fine with the SendMessage action. Do I need to create a custom action perhaps?

Thanks!

Clockwork Wolf

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Calling Public Functions with multiple variables
« Reply #1 on: September 02, 2013, 11:43:09 PM »
.... the custom action seems to be the way to go!

Code: [Select]
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
public class customPMAction : FsmStateAction
{
public FsmGameObject gameObject;
public int lightDamage = 20;
public int darkDamage = 20;

// Use this for initialization
public override void OnEnter () {
if (gameObject.Value!= null)
{
gameObject.Value.GetComponent<PAClass>().damage(darkDamage,lightDamage);
}

Finish();
}

// Update is called once per frame
public override void OnUpdate () {

}
}
}

Sorry for the bother!

Semihero

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Calling Public Functions with multiple variables
« Reply #2 on: September 05, 2013, 08:38:26 AM »
Dear Clockwork Wolf,

No matter if you could find it out yourself or not, I think this is a valid possibility of making Playmaker even better. I think passing multiple variables through Send Message would be a great help to have.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Calling Public Functions with multiple variables
« Reply #3 on: September 05, 2013, 09:52:47 AM »
There's a new Call Method action in 1.7.3:
https://hutonggames.fogbugz.com/default.asp?W1139

More documentation and tutorial videos coming soon...