• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Discussion An argument for the return of object_add in GMS2

C

Chris

Guest
I loved the functions that allowed you to create objects dynamically. They've been obsolete for a long time, but I think that they could still be valuable if ever reimplemented. Being able to dynamically create objects made it easier to make GML extendable, simply by having a programatic way to access events through dynamic events.

One such use case would be a wrapper script for async functions that allowed you to supply a callback parameter. Something like this:
Code:
///showMessageAsync(msg, callback)

//msg (string) - Message to display
//callback (string) - Script name as a string (without parentheses)

//Get arguments
var scr = argument1;

//Dynamically create an object
var callbackObj = object_add();

//Add the message
object_event_add(callbackObj, ev_create, 0, "msg = show_message_async(" + argument0 + ");");

//Setup the callback (note that ev_async and ev_dialog do not exist, but they should!
object_event_add(callbackObj, ev_async, ev_dialog,"
  if (ds_map_find_value(async_load, "id") == msg) {
    if ds_map_find_value(async_load, "status") {
      script_execute(" + scr + ");
      instance_destroy();
      object_delete(id);
    }
  }
");

//Add the object to the room
instance_create(0,0,callbackObj);

Even if we can't dynamically create objects, it would be nice to have access to events programmatically maybe in some other ways.

Is this something that's been considered for the future of GML? Or maybe some other extendable features? Maybe I'm just trying to use GML too much like JavaScript.
 

Mike

nobody important
GMC Elder
Not gonna happen.....

But nothing stopping you having an object template where each event has a script ID. If it's -1, then just exit, otherwise call it. Hay presto - dynamic objects.
 
C

Chris

Guest
Not gonna happen.....

But nothing stopping you having an object template where each event has a script ID. If it's -1, then just exit, otherwise call it. Hay presto - dynamic objects.
Yeah, that's true. That's how I've done it in the past. I just figured it was nicer to do it programmatically so you could reduce the amount of resources to import for extensions that did it this way.
 
Top