[Solve] Set Global Variable from a Scene

Hi guys,
So I have a timer running on a level and it all works, when you end the level, I have this to set the GV:
image

Then on the start page, I have this to show the new GV or the time I just set:
image

As you can see, the end is not green, any ideas of what I am missing?
Thanks
Jimmy

I am not at my computer right now, but I think GlobalVariableString looks for only string variable s, and you are using a numberr/integer variable.

You might need to use ToString(GlobalVariable())…but I cant remember if that is the right syntax or not.

2 Likes

Are you manually typing your expressions? I’d recommend using the expression finder if not. I can’t reproduce the issue you’re having.

1 Like

I used the expression finder for the first entry.
image

now I have 3, none are green:
image

Thanks again.

Grey is normal. The color is different because one is a number type and the other is a string type.
What matters is that when you edit it, it shows blue and not red.

3 Likes

If this is just about the event color, I feel very foolish now. I was reading this entire thread as “The text isn’t changing from these events” not “the color of this event is different”.

Jimmy, chime in if these events are working or not.

You cannot write a text field to a Global or Scene Variable.

Writing text:
image

Cannot save it to GV or SV:
image

Any advice please?
Thanks
Jim

The first expression: Variable(level1timer) what is it? A scene variable named “level1timer”?

Done, it but its based on frame rate:
image

Hi, yep, level1timer is a Global and Scene Variable.

If anyone can think of a better way to record time, that would be amazing.
Thanks

Ok, so with “r” is a scene variable and without “r” a global variable? And are you sure the scene variable works?

Wait, looking back through these events I’m confused. Where is your timer being set up?

To be clear, changing a variable with “Add 1” isn’t a timer, that’s just constantly adding 1 to a variable, and can be variable based off the framerate the game is running at.

Are you actually using a timer somewhere?

Edit: Also, I’ve tested every method I can think of with Variables to TextObjects. They all work

image

1 Like

Thanks a lot. Yes, I am using the frame rate.
I will try your code, thanks again.
Jim

Thank you, it works.
I needed this code: ToString(TimerElapsedTime(“level1timer”))
I added ‘round’: ToString(round(TimerElapsedTime(“level1timer”))) to get it to a single digit when displayed, but when written to the GV, it has 16 extra digits!
Do you know how to display and write it as 0:00 not 0:0000000000000000?
Thanks again
Jim

round(TimerElapsedTime(“level1timer”)) to set the GV.

This thread has some information about using trunc() to get specific decimal points: [Solved] Decimal places

Thanks, its not working yet, I have this, I will keep trying:

"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”))*100/100)
"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”)*100/100))

Its still 1 digit.

You have your /100 in the wrong place. Move it outside of the next ).

1 Like

4 variations, Still no luck.
"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”))*100/100)
"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”))*100)/100
"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”)*100/100))
"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”)*100)/100)

image

Hmm…something’s still off with your formula, because I was able to get 2 decimals. Here you go:

image

Here’s the editor for the value:

1 Like

You are an absolute star!
it worked
"Time: " + ToString(trunc(TimerElapsedTime(“level1timer”)*100)/100)
The only thing I did differently, was to type it not copy paste?
Anyway, thanks again bud!
Jim

1 Like