playMaker

Author Topic: Accessing Playmaker Variables in UnityScript  (Read 2138 times)

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Accessing Playmaker Variables in UnityScript
« on: November 18, 2013, 09:31:16 PM »
I've been going crazy trying to solve this issue, and I have it down to a cause, but no solution (typical of my work it seems). Sorry for the long-winded question, just want to give all the information needed.

Details: I'm using PlayMaker FSMs to control character movement. I've added a modified version of the "FPS Walker Enhanced" script - I gutted everything regarding character movement, except the bits that control jumping and sliding down steep slopes (an undertaking by itself).

When the character jumps, the script takes over and only accounts for the character's movement in the Y direction - and therefore any movement in the X or Z directions remains the same as when the character left the ground (inertia).

I want to be able to control the character in-air. Doing so via the script sounds easy, and it even comes with a few lines to do so, but I've spent weeks struggling with it. Since the script references the character's X and Z movement separately from the Playmaker FSMs, it was causing the built-in in-air controls to behave very oddly.

I think the solution is to reference the Playmaker FSM's stored variables, and plug them into the script. I've seen this asked before on the forums, (thanks again Jean!) but I'm not able to get it working.


Problem: Using the script below, I get the compiler error "Unexpected token: :. ", likely because I'm trying to get the X and Z components of the FSM string I'm referencing and Unity doesn't like that.

I've included an image of my FSM which moves the character.

Here's the script, I tried to take out the boring bits that aren't related to the issue for your convenience :P

import HutongGames.PlayMaker;

function Start () {
// get the global variable pointer
var pmove:FsmString = FsmVariables.GlobalVariables.FindFsmString("Player Movement");
}


function FixedUpdate() {

if (grounded) { stuff that enables sliding, etc

// Jump! But only if the jump button has been released and player has been grounded for a given number of frames
if (!Input.GetButton("Jump"))
jumpTimer++;

else if (jumpTimer >= antiBunnyHopFactor) {
moveDirection.y = jumpSpeed;
moveDirection.x = pmove:FsmString.x;
moveDirection.z = pmove:FsmString.z;

playerControl = true;
jumpTimer = 0;
      }

Any ideas/advice greatly appreciated!
« Last Edit: November 18, 2013, 09:44:20 PM by Breadman »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Accessing Playmaker Variables in UnityScript
« Reply #1 on: November 18, 2013, 10:20:27 PM »
Try pmove.x instead of pmove:FsmString.x

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Accessing Playmaker Variables in UnityScript
« Reply #2 on: November 18, 2013, 11:27:10 PM »
Hi Alex,

Thanks so much for your reply!

I tried just "pmove.x", after which the compiler told me it couldn't identify the variable. So I then also changed the "var pmove:FsmString =..." to just "var pmove = ...", which stopped the compiler from giving me the error.

Oddly, despite no compiler errors, when the game runs everything is fine - until I hit the jump button and the game pauses itself. I can unpause it, and things continue as normal, until I try to jump again, at which point it pauses itself. Even weirder, is that the console remains silent during this process.
« Last Edit: November 18, 2013, 11:29:35 PM by Breadman »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Accessing Playmaker Variables in UnityScript
« Reply #3 on: November 19, 2013, 12:00:42 AM »
pmove is a local variable only visible inside Start since that's where you declared it. Move it outside of Start and it should be visible in other methods...

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Accessing Playmaker Variables in UnityScript
« Reply #4 on: November 19, 2013, 12:22:02 AM »
Thanks for the tip, makes total sense. Sadly, even when declaring the variable in the fixed update function, the game pauses itself. I wonder what's going on?