The 2.3.8 beta has added the ability to synthetically perform the Pre-Create event, which allows for
a new solution better than all others before it. When and if 2.3.8 stable gets released without major issues, I will release the solution as a free library, and there won't be any need for tutorials on this issue again.
Hey, that sounds exciting! I'll be keen to try as soon as I'm able.
I regret to inform that you could always synthetically run Pre-Create using event_perform(14,0) - I used this in GMRoomPack
Would you happen to have more info on this technique event_perform(14,0) ? I had a look through the manual but couldn't find any numeral identifiers, so not sure what 14 and 0 refer to?
I've spent this evening attempting to use event_user(0) but it always results in my creation event executing twice and then causing a crash. Objects at the start of my game run as expected when referring to event_user(0) via their create event, but then again, when I try to create_instance it calls the original create event, which then calls event_user(0), and my object then gets confused with itself as it runs creation code twice, once incorrectly and the second time correctly... >_<
EDIT: Oh wow, reading through the Beta thread after searching for ev_pre_create , I'm hopeful that this will be what I'm after!
@FrostyCat , your JSON-esk method looks perfect too. Very keen to try it.
I can't find any actual examples of how to use ev_pre_create, so would be keen for an example if anyone has one.
EDIT 2: Woop, figured out what
I think may be an alternative workflow? It's probably done by others somewhere, but not that I found during my reading - but in my quick testing it seems to work. In summary, I need two methods to create an object. 1) when the room starts and 2) when an object collides with another object. Both creation methods are the same with exception to a couple of simple variables. So looking through the events whilst researching ev_pre_create, I found an event called "Room Start" which I can use to host my creation code for objects that start life in the room. And for objects created during the game, the User Events work well to run that particular code.
I think this method might do me whilst we wait (pray?) for YoYo to add some kind of Object Creation argument injection into GMS2. Again, the way FrostyCat had an example (and apologies if I've misquoted) ;
GML:
new_obj = instance_create_layer(_x,_y, "Instances",obj,
{
animal = "cat",
age = 7,
name = "Mr Kitty Cat"
}
);
That would be the ultimate solution.
EDIT 3: Just confirming, that having creation code moved into a Room Start event, and also a User Event, this seems to work well. Below is one "obj_Animal" object with a white sprite. The sprite colour is adjusted by image_blend and the _animal variable set in each relevant event.
Variable init; _animal = None
Create Event; _animal = "Mouse"
User Event; _animal = "Dog"
Room Start Event; animal = "Cat"
So a catch for using this method - anything that's defined in the Create Event will be executed, so all animals start life out as a "Mouse" in this example - which could lead to code crashing issues. So no animal should be defined in Create Event.