Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

GMLive.gml

Livecoding for GameMaker: Studio / GameMaker Studio 2 · By YellowAfterlife

Problem with global variable

A topic by PolyCrunch Games created 58 days ago Views: 63 Replies: 4
Viewing posts 1 to 2

Hi,

In a step of an object I was seeing 

[live][16:14:27] Runtime error: obj_Boulder:Step_0[L2,c15] obj_Boulder:Step_0[L2,c15] Can't add number and undefined

The offending code was this:

verticalSpeed += global.gravity;

If I replace the global variable by some literal value the error goes away. The global variable in question is declared in an initialisation script but even if I do a show_debug_message it is being shown as undefined. Is there some problem with global variables being used in "live" scripts?

Developer

May need a slightly bigger snippet of code to look at - the documentation has a list of things that don't work the same under the "limitations" section.

hmmm, could a recent GMS2 update have broken something?  I've run into something similar that I'd swear wasn't happening before.  I'm doing something like:

//obj_main (any event, even a step event)

enum keys {left}

#macro KEYS global.key_array

#macro KEY_LEFT KEYS[keys.left]

//obj_input (step event)

if (live_call()) {return live_result;}

KEYS[keys.left] = keyboard_check(vk_left);

show_debug_message(KEY_LEFT);

...and ending up with errors.  When I try to do anything involving the KEY_LEFT macro it says a variable named 'KEYS' doesn't exist, then if I change the macro to #macro KEY_LEFT global.key_array[keys.left] it instead tells me a variable named 'keys' doesn't exist, but if I make it just plain #macro KEY_LEFT global.key_array[0] then it works just fine

BUT, if I put the enum line and the #macro KEY_LEFT KEYS[key.left] line in the step event above the keyboard_check line in that step event, it suddenly works??

I'd SWEAR I used to be able to do this no problem, it's not doing anything super crazy with the macros, just trying to use another macro pointing to a global and an enum and the fact that once I put the lines in the event doing the "if (live_call())" suggests that it's definitely not a problem for GMLive since it works when I do that.


I checked with some super old versions of my game that I'm 99% sure I was editing this way just fine and now I get the "can't find a variable" thing.  GMS2 has gone through a lot of updates lately, maybe they juggled something around internally and it's messing with globals/enums/macros that's affecting GMLive?

I'll do up a test project for you when I get some downtime, but wanted to rough out this description incase it's related to the same problem as the above poster and incase it gives you an idea of something that could've happened to dig into!

P.S. on the plus side I'm the guy who's GMS2 wasn't letting him drag & drop the GMLive extension on it to install and kept needing a special version to get it to install, and the Import Local Package feature they added a few updates ago totally gets around that problem so it's nice and easy to install in new projects now :)

Developer

A project file would be helpful, yes. I figure that I'll need to rewrite macros to work closer to how they do in GM after all.

(+1)

Whipped up a bare-bones project file for you: http://bulletproofoutlaws.com/junk/gmlive_bug.yyz

It's just got an input handler object and a player object.  If everything is inside the player object it'll work, but obviously that's not really practical lol  I'd swear this used to work just fine and doesn't break any of the GMLive complicated macro limitations...it just seems to not be able to find the global array if it's not created inside the object trying to do something with it while using GMLive

Hope that helps narrow it down!