playMaker

Author Topic: Easy way to view / expose variables at runtime testing?  (Read 3166 times)

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Easy way to view / expose variables at runtime testing?
« on: July 26, 2018, 12:21:38 AM »
Hi everyone,

So something I was used to having in Construct was a debug mode where you saw the game and in a window below could see all of the global variables values change in real time..   this was really handy to quickly assess if various logic / math was firing off correctly, especially when you might have numerous global variables managing various game states..

 In my first flappy bird iteration I managed hack something together showing a single variable, but if i have 5-6 this seemed like a really messy way making a text field for each and having to update them all with their own playmaker events / states /etc...

I was hoping maybe this can be done in some view I'm unaware already.  It seems like Unity itself would offer something like this as well, I just haven't see it anywhere. 

Thanks!
Caleb

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Easy way to view / expose variables at runtime testing?
« Reply #1 on: July 26, 2018, 12:55:16 AM »
You can store them in local variables and then simply expose them in the FSM inspector. You can even display them on screen that way and toggle that FSM on and off and make yourself a nice debug mode.
Available for Playmaker work

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Easy way to view / expose variables at runtime testing?
« Reply #2 on: July 26, 2018, 01:02:58 AM »
I think I follow but could you explain how that works?

Are you suggesting I send my global variables over to a local variable (every frame or at least with each event change)

Is there not a way to expose a global variable as a global variable?  It sounds like you're saying it's not.. except by forcing the global over to a local var for the sake of displaying..

You mention displaying them on screen.  do you mean by using a text object?  That's how i did it last time with one, but it seemed like it could get messy if i needed to track multiple objects with multiple states potentially. 

Lastly maybe you're suggesting i make a "debug" object that holds all of these values and then enable / disable it as needed when it's time to test? 

Thanks!
Caleb

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Easy way to view / expose variables at runtime testing?
« Reply #3 on: July 26, 2018, 01:50:08 AM »
I'' make you a small example project later, ok?
Available for Playmaker work

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Easy way to view / expose variables at runtime testing?
« Reply #4 on: July 26, 2018, 01:59:13 AM »
that would rock! :)   

I could learn a lot from that, not just in this example but interacting with a project setup by someone else who knows what they are doing!

I kinda feel like as I get deeper into a game (and when I say deep i'm talking flappy bird deep) it starts to get a little confusing where I tucked which thing away..

one of the oddest things is that I make this local variables for specific instances, but then there doesn't seem to be a way to find those local variables to delete them (which i would should be in the local FSM variables tab) but that's probably another thread to get into..  heh

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Easy way to view / expose variables at runtime testing?
« Reply #5 on: July 26, 2018, 04:33:45 AM »
Here you go: https://www.dropbox.com/s/u2sdd98j0jf22il/Playmaker.rar?dl=0

Bear in mind some things are reduntant for the sake of explaining multiple ways to do the same thing. Here's how things work:

You have an object named Debug in the scene, it holds TextMeshPro for displaying variable data in string form as well as two FSM's, DebugButton and ScoreDisplay. We have an Int Score Global variable and Int ScoreLocal variable as well as string ScoreString variable for display purposes.

DebugButton controls the displaying of Score by using D key. You can toggle it on and off. There is a slight wait between toggle so the states don't enter the loop since i'm using get key and bool, though you can use get key down without the wait for such simple things. When its on, it enables ScoreDisplay FSM, when it's off, it disables it and sets TextMeshPro text to blank.

ScoreDisplay FSM converts Int Score Global variable to ScoreString so we can feed the TextMeshPro with string for display purposes. I used Format string to add "Score" in front of the ScoreString variable so you know what data you're looking at.

Last action, Set Int Value is redundant, but server for demonstration purposes. Bear in mind that Convert Int To String gets GLOBAL int variable, you can use Set Int Value to "copy" global to local variable every frame and use it instead, but more importantly, you can expose local variable in the inspector of the ScoreDisplay FSM, you can't do that with global.

So basically, you can copy the values of all the global variables you're using to local in one FSM and check the Inspector button in the variables menu of the FSM to show them in the inspectorm or make a display of them on the screen with TextMeshPro.

Quote
one of the oddest things is that I make this local variables for specific instances, but then there doesn't seem to be a way to find those local variables to delete them (which i would should be in the local FSM variables tab) but that's probably another thread to get into..  heh

No way that's happening, if you made a local variable, it's available for editing in the prefab/instance. I made similar mistakes when i was starting, you're probably using a global variable and think that it's local. Go to globals and see where they're used.
Available for Playmaker work

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Easy way to view / expose variables at runtime testing?
« Reply #6 on: July 26, 2018, 04:26:16 PM »
Thanks for this.  I opened it up a few times today and I'm not sure if I'm seeing the right stuff.  This makes sense doing what you demonstrated.  I like the toggling.  I'm going to have to look at that closer because I know in construct i used Modulo operations to help manage "on / off" states. 

So to be clear there is no way to just "view" local or global variables in real time all at once without having to setup a specific text field in the game to watch through the game itself?  I mean imagine if you had a game that had 6-12 different game states.  Like..  "has game started?"   "is game paused?"    "has the game ended?"  and other various values that may matter when testing a game..   you have to setup text fields in-game for each one of those?

That was my real hope.  That I could just see the current values of various global variables in real time change.. like when i'm trying to figure out if my math is working..   

i ask because i'm trying to make my flappy bird test game know "game has started" and when the player hits something i want to say "Game is over" and lock it so no further game button press..  when things don't work i find it really helpful to know if the variables i'm setting are in fact changing..  when i debug it, it lets me know if the issue is before that moment or after..



As for the missing variables, I'll make a new thread if I come across that problem again.  Maybe I did make a global, but if I did that i'd see it under the global variables..   I remember it pretty vivid because here is what i was seeing.  Somehow I had made a two (what i thought were) local variables that were basically redundant and I couldn't find either of them in the variable tab of the particular FSM..  it was weird.. 

Thank you so much for this insight and example!  :) 

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Easy way to view / expose variables at runtime testing?
« Reply #7 on: July 28, 2018, 04:28:27 AM »
Sure you can, check "inspector" button for each local variable you want exposed and then you can see it during runtime by clicking on an object. FSM component will show variable values in inspector.

As for globals, you can watch them on runtime too in the global variables window.

Displaying variable values on screen is a simpler way to monitor local and global variables from different game objects without the need to enter FSM's.

Or! You can forward all variables to local variables in one FSM, check inspector and you have them all in one handy inspector.
« Last Edit: July 28, 2018, 06:22:52 AM by krmko »
Available for Playmaker work

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Easy way to view / expose variables at runtime testing?
« Reply #8 on: July 28, 2018, 10:42:55 AM »
Ah ok i'm going to try that and see how it goes.  knowing what variables are changing and when and seeing it in real time is really helpful.. i just couldn't see that.  Never noticed global vars changing..

It felt like a drag to have to build out FSMs to see this kind of information so I'm glad that's possible!  :) 

Thanks!
Caleb