Pages: 1
Author Topic: Instance Creation Codes  (53,996 Views)
Offline (Unknown gender) Benxamix2

Member
Joined: Mar 2012
Posts: 69
View profile WWW
Posted on: May 14, 2014, 02:38:15 AM
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.
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #1 Posted on: May 14, 2014, 03:35:16 AM
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
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #2 Posted on: May 14, 2014, 03:28:08 PM
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.
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #3 Posted on: May 14, 2014, 06:44:20 PM
Yes Harri, you are correct, but Studio also does it backwards like we do for the same reason, I think.
Offline (Unknown gender) Benxamix2

Member
Joined: Mar 2012
Posts: 69
View profile WWW
Reply #4 Posted on: May 14, 2014, 10:33:34 PM
Quote from: Robert B Colton on May 14, 2014, 03:35:16 AMCreate->Instance Create->Game Start->Room Create->Room Start

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


Quote from: TheExDeus on May 14, 2014, 03:28:08 PMAlso, "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.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #5 Posted on: May 15, 2014, 11:18:08 AM
Try just text = "something" without the useless "local variant" stuff. Maybe it's a type bug in parser or something.
Offline (Unknown gender) Benxamix2

Member
Joined: Mar 2012
Posts: 69
View profile WWW
Reply #6 Posted on: May 15, 2014, 09:11:20 PM
Quote from: TheExDeus on May 15, 2014, 11:18:08 AM
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.
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #7 Posted on: May 15, 2014, 11: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.



Offline (Unknown gender) Benxamix2

Member
Joined: Mar 2012
Posts: 69
View profile WWW
Reply #8 Posted on: May 16, 2014, 12:31:09 AM
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.
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #9 Posted on: May 17, 2014, 02:09:03 PM
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?
Offline (Unknown gender) Benxamix2

Member
Joined: Mar 2012
Posts: 69
View profile WWW
Reply #10 Posted on: May 18, 2014, 12:57:50 AM
Quote from: Josh @ Dreamland on May 17, 2014, 02:09:03 PMAnother 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).


Quote from: Josh @ Dreamland on May 17, 2014, 02:09:03 PMSo, 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!
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #11 Posted on: May 18, 2014, 02:35:23 PM
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.
Pages: 1