Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Issue Accessing Game Assets from Live Snippets

A topic by KingTremolo created Oct 10, 2021 Views: 233 Replies: 3
Viewing posts 1 to 3
(1 edit)

Hello,

I am in the process of porting a game from GM8.0 to GMS2.3. Against the recommendations of Yellow AfterLife, I am using GMLive to load external code for some of the game logic. In GM8, we used custom objects extensively to load arbitrary external content. The game is treated like a MUGEN of its respective genre, and its users quite like the full GML support, so we need to keep access to full GML.

My issue is that I am unable to access assets in the asset tree from code compiled using live_snippet_create.
For example, I have

object.scr_step    = live_snippet_create(stage_scr_load("scr_step"));

Which reads the code form a file into a string to compile and cache into a snippet.

In that code I have 

with ( obj_stage_bg ) {   // My Code here }

With obj_stage_bg being a GameMaker object. This code does not work however, as it gives me the following error:

[error] 100009 (obj_game_control) does not have a variable `obj_stage_bg` called from execute_string[L56,c8]

Until the need for the with statement I've gotten around this but "installing" scripts and such to variables in the calling objects using asset_get_index(), but that hasn't been working for the with statement.


EDIT: I don't know what I was thinking, asset_get_index is indeed working for it. However, I would still like to know if there is some setup I can do to do this stuff directly. I have thousands of scripts to port, so it would be a huge help!


Thoughts on why I cannot access my assets from GMLive code? And if this is expected behavior, is there anyway I can get with statements to function properly? Thank you.

Developer

If you are using GMLive for code execution, you’ll still want to call live_init, but with undefined for server URL.

You may also add constants manually via live_constant_add.

Thank you kindly! For the server URL setting it to undefined caused it to error on start with something about a recursive struct, however an empty string did the trick.

OK so the blank string made it work in some cases, and yet in others I seem to have objects that are not being found without wrapping in asset_get_index