PlayMaker Help & Tips > PlayMaker Help

[SOLVED] Help with timer script

(1/2) > >>

Lobohotpants:
I was wondering if you guys could help me with creating an action or use existing actions that can access this timer script and create a controller instead of having to write the code.  It came with js and cs scripts but the tutorial was written in js.  I could copy the js but my project is using all cs and I have a feeling mixing the two is probably a bad idea.  That's where I ran into trouble.  I don't know cs syntax so everything I tried to import had parsing errors.

What I need is really simple.  I need to be able to access the timeString, turn the timer on and off and fire events every second.

This is all pretty new to me so any help is appreciated.

jeanfabre:
Hi,

 ok, I had a go at your Timer, and provided a working example hiliting several technics.

1: I created a proxy  "TimerProxy" so that you can receive the timer callback and fire a playmaker event as a result
2: I created a custom action "TimerGetFormattedTime" to call that function and get the result

So you'll find in the attached package a fully working system using this timer and how it can be integrated with playmaker.

WARNING: I modified the timer script because it doesn't work otherwise ( not related to playmaker, just the internal logic was wrong), I am not sure why this was so, Also the time information you get is not really about the count down, so more work here is needed to get this Timer system right.

Note that the timer could expose more variables publicly and it would void the need to create specific actions, and you would simply use the "get property" action to access string representations of the time, and various other features.

If you have more questions, don't hesitate, this is very important aspect of playmaker integration with existing framework and scripts.

Bye,

 Jean

Lobohotpants:
Hey thanks for taking a look at it.

I loaded up your example and saw what you did.  I didn't fully understand how it worked until this morning so maybe I can help you with the logic issues you were talking about.  It looks to me like the timer script stays in the project folder and you don't actually attach it to anything in the game manually.  The controller script attaches the timer script to the gameobject at runtime so that could be why it wasn't working? 

I'll attach the unitypackage so you can see how it all works though the controller example included is in js.

After I figured out how it works I tried setting the included controller script on a gameobject, setting up an FSM and trying to getProperty of the controller script.  I could access the public variables and even exposed some that were private but when I changed the values it didn't seem like it did anything.

Then I tried piecing together a cs controller using a js to cs converter.  Very handy!  This is what I came up with that seemed to work but again I couldn't access it with getProperty.

--- Code: ---using UnityEngine;
using System.Collections;



public class Controller : MonoBehaviour {
public Timer timerObj;
public string timeString;
public float timeScaleFactor = 1.0f;

// Use this for initialization
void Start () {
// create timer and attach to this gameObject
timerObj = gameObject.AddComponent<Timer>();
timerObj.StartTimer();
}

// Update is called once per frame
void Update () {
// grab our time strings from the timer objects
timeString= timerObj.GetFormattedTime(2);
// dump it to the console
Debug.Log(timeString);
}
}

--- End code ---

jeanfabre:
Hi,

 What exactly are you trying to access with getProperty? I am little confused.

 Bye,

 Jean

Lobohotpants:
Haha I'm also a little confused.  ??? Maybe I'm not understanding fully how to use getProperty but like I said in my original post I just need timeString, turn the timer on and off and fire events every second.

What I was trying to do in the previous example was change the timescale by using getProperty and it didn't seem like it was working.

Navigation

[0] Message Index

[#] Next page

Go to full version