ENIGMA Forums

Outsourcing saves money => Programming Help => Topic started by: Benxamix2 on May 13, 2014, 09:38:15 PM

Title: Instance Creation Codes
Post by: Benxamix2 on May 13, 2014, 09:38:15 PM
Hey there! I'll be straightforward.
I'm making multiple instances of an object in the same room. I want, however, to keep a specific variable different on each of them. I've set Instance Creation Codes in the room editor for this, but it seems to crash my game, "because there's an unspecified variable". I've made enough self-debugging in order to understand that this is what causes the error.

My question is: could you tell me the order of execution of these events, for future reference?
Instance Creation - Create - Room Start

I'm assuming it's the one showing up but I'm not sure.
However, if I'm right, I'd suggest to switch Instance Creation and Create, if possible. I don't see the point of it being different than that.
Title: Re: Instance Creation Codes
Post by: Goombert on May 13, 2014, 10:35:16 PM
I'm pretty sure that is correct, you may have Instance Create and Create backwards.
https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Universal_System/roomsystem.cpp#L168

So Create->Instance Create->Game Start->Room Create->Room Start
Title: Re: Instance Creation Codes
Post by: TheExDeus on May 14, 2014, 10:28:08 AM
I think "Instance Creation - Create" was how GM did it.
We have it the other way around (it is more logical, as you want to change variables that are already defined).

Also, "because there's an unspecified variable" should not crash your game. It should only show in debug mode and even if you press Ignore it should run. But you are right that you should fix them.
Title: Re: Instance Creation Codes
Post by: Goombert on May 14, 2014, 01:44:20 PM
Yes Harri, you are correct, but Studio also does it backwards like we do for the same reason, I think.
Title: Re: Instance Creation Codes
Post by: Benxamix2 on May 14, 2014, 05:33:34 PM
Create->Instance Create->Game Start->Room Create->Room Start

That's something I won't forget, now.


Also, "because there's an unspecified variable" should not crash your game. It should only show in debug mode and even if you press Ignore it should run. But you are right that you should fix them.

Well, it does.

The only reason my game's crashing now is because I set custom instance creation codes, so to change already declared variables. I've debugged it by simply duplicating the room and deleting every instance's creation code, then running that new room first, so that every instance is set to default values.

In this case, I'm using the following in my Object Create Event:

Code: (EDL) [Select]
local variant text="This is the default signboard text. If you're reading this, it's a bug. So please, tell my moron creator to fix it!";

And this is how a single instance code looks:

Code: (EDL) [Select]
text="Welcome to the first PIT² BETA! Move around with the arrow keys, and jump with the Space bar!";

To put it simple, again: if I do not use instance creation codes, my game works flawlessly. If I do, it crashes instantly when the room starts.
I wasn't sure before, but I'm starting to think this is an ENIGMA bug.
Title: Re: Instance Creation Codes
Post by: TheExDeus on May 15, 2014, 06:18:08 AM
Try just text = "something" without the useless "local variant" stuff. Maybe it's a type bug in parser or something.
Title: Re: Instance Creation Codes
Post by: Benxamix2 on May 15, 2014, 04:11:20 PM
Try just text = "something" without the useless "local variant" stuff. Maybe it's a type bug in parser or something.

I wish it was. It didn't work, either...
But I found out it works as long as I don't use strings.
I've just submitted it to the bugtracker.
Title: Re: Instance Creation Codes
Post by: Darkstar2 on May 15, 2014, 06:11:57 PM
I can't reproduce your error, it works fine for me.

I created 3 different instances of the same object inside a room, noted the instance ID of each, then on each different instance I added a text string into the instance creation code.  I copy/pasted your example, and for the other 2 used my own.

Then in the main object's draw event I added this debug to see if it works.

draw_text(10,10,string(100010.text));

This displayed
Welcome to the first PIT² BETA! Move around with the arrow keys, and jump with the Space bar!

draw_text(10,10,string(100011.text));

This displayed the other text string I used.

and so forth, so I could individually set variables to
each instance ID.  TO access these you precede the
variable with the instance ID as shown above.

With or without draw event, no crashes here.



Title: Re: Instance Creation Codes
Post by: Benxamix2 on May 15, 2014, 07:31:09 PM
That just makes it weirder.

This was my code in the Draw Event. It does not work.

Code: (EDL) [Select]
draw_text_ext(view_xview+160,view_yview+112,text,-1,200);

But if I do this, similar to you, it does... At least it doesn't crash, and it does shows a text.

Code: (EDL) [Select]
draw_text_ext(view_xview+160,view_yview+112,100174.text,-1,200);

But, since I'll be having more than 1 signboard in the same room, and this only shows a single one's message... It's kind of a workaround, but does not serve to my purpose.

It doesn't work with self.text, or string(text) either.
Title: Re: Instance Creation Codes
Post by: Josh @ Dreamland on May 17, 2014, 09:09:03 AM
So, Robert recently edited the draw_string function. It wouldn't surprise me if it crashes your game when passed an empty string or an uninitialized variable. Could you verify this by drawing string(string_length(text))? That will at least tell us what's going on.

Another item to consider is the fact that your string contains a "²" character. Did you modify your font to contain this glyph? Does it crash in debug mode? What happens if you remove this glyph?
Title: Re: Instance Creation Codes
Post by: Benxamix2 on May 17, 2014, 07:57:50 PM
Another item to consider is the fact that your string contains a "²" character. Did you modify your font to contain this glyph? Does it crash in debug mode? What happens if you remove this glyph?

That fixed it...
Gosh! I feel dumb now!
Forgot that character wasn't in the default font's char range (and I cannot change that anyway, so DAMN).


So, Robert recently edited the draw_string function. It wouldn't surprise me if it crashes your game when passed an empty string or an uninitialized variable. Could you verify this by drawing string(string_length(text))? That will at least tell us what's going on.

(Un)Surprisingly enough, it works and does draw the string's length.


Thank you, Josh!
Title: Re: Instance Creation Codes
Post by: Josh @ Dreamland on May 18, 2014, 09:35:23 AM
That's actually something we should probably run checking for, even outside debug mode. A null check after that lookup is basically free, and malformed strings happen all the time.

Anyway, no problem.