playMaker

Author Topic: How do I access a static var from a script?  (Read 2105 times)

artfish

  • Playmaker Newbie
  • *
  • Posts: 5
How do I access a static var from a script?
« on: October 18, 2014, 07:14:05 PM »
Hello! Ok, I just started using Playmaker again a few days ago and I've generally been able to figure most things out so far. Here's what I'm struggling with right now. I have this simple script keeping track of  how much time has elapsed in my game.
I want to be able to use Playmaker to check if static var hour is > "X".

I watched the connecting scripts video and have read a bunch of stuff, but I'm still struggling. Any help would be much appreciated! Thanks!

    var lastChange = 0.0;
     
    static var hour = 6;
    static var minutes = 0;
    var ampm = "am";
    var myStyle : GUIStyle;
   
     function Update () {
        if (Time.time - lastChange > 10.0) {
            minutes++;
            if (minutes == 6) {
                minutes = 0;
                hour++;
                if (hour == 12) {
                    if (ampm == "am") {
                        ampm = "pm";
                    } else {
                        newDay();
                    }
                }
                if (hour == 13) {
                    hour = 1;
                }
            }
            lastChange = Time.time;
        }
    }
     
    function OnGUI () {
    GUI.depth = 0;
        GUILayout.Label(hour.ToString() + ":" + minutes.ToString() + "0" + ampm, myStyle);
    }
     
    function newDay () {

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4003
  • Official Playmaker Support
    • LinkedIn
Re: How do I access a static var from a script?
« Reply #1 on: October 19, 2014, 12:28:37 AM »
Get/Set Property doesn't work with static variables yet.

So you'd need to write a small custom action to access the static variable... shout if you need help making this.


artfish

  • Playmaker Newbie
  • *
  • Posts: 5
Re: How do I access a static var from a script?
« Reply #2 on: October 19, 2014, 11:54:30 AM »
Hey Alex, thanks for the reply and thanks for the offer to help.
Basically, I'm trying to trigger random events based on what time of day it is.
I figured that time script I'm using for the clock would be a good way to start, not really knowing if their is a way or a better way to do this within Playmaker already.

Maybe you could help me figure out if this is the best way to go about doing it.

Ok, I'm going t o have about 30 different objects with FSMs that are listening for their own number, to fire off. At certain times of the day, let's say every half hour, (30 seconds in game time) I will generate a random number between 1 and 30. Each FSM will be listening for that random number and if the number matches, then it will allow the rest of the FSM to be executed.

Or, I could just continue doing my original path and request a little help with you helping me figure out how to make a custom action.

Regardless, thanks for your time!


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4003
  • Official Playmaker Support
    • LinkedIn
Re: How do I access a static var from a script?
« Reply #3 on: October 19, 2014, 03:44:38 PM »
Take a look at the GetTimeInfo action. That gives you info like "Time In Current State" or "Time Since Startup". You can use those to trigger random events using FloatCompare.

If you need real world time, take a look at GetSystemDateTime. This returns a string, so you'll need to do some work to get numbers (hint: use GetSubstring and ConvertStringToInt). There may also be some custom time actions on the forums...