Pages: 1
  Print  
Author Topic: Instance Creation Codes  (Read 2124 times)
Offline (Male) Benxamix2
Posted on: May 13, 2014, 09:38:15 PM

Member
Location: Chile
Joined: Mar 2012
Posts: 69

View Profile WWW Email
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.
Logged
Offline (Male) Goombert
Reply #1 Posted on: May 13, 2014, 10:35:16 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3107

View Profile
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
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #2 Posted on: May 14, 2014, 10:28:08 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
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.
« Last Edit: May 14, 2014, 02:33:09 PM by TheExDeus » Logged
Offline (Male) Goombert
Reply #3 Posted on: May 14, 2014, 01:44:20 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3107

View Profile
Yes Harri, you are correct, but Studio also does it backwards like we do for the same reason, I think.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) Benxamix2
Reply #4 Posted on: May 14, 2014, 05:33:34 PM

Member
Location: Chile
Joined: Mar 2012
Posts: 69

View Profile WWW Email
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.
« Last Edit: May 14, 2014, 08:53:17 PM by Benxamix2 » Logged
Offline (Unknown gender) TheExDeus
Reply #5 Posted on: May 15, 2014, 06:18:08 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Try just text = "something" without the useless "local variant" stuff. Maybe it's a type bug in parser or something.
Logged
Offline (Male) Benxamix2
Reply #6 Posted on: May 15, 2014, 04:11:20 PM

Member
Location: Chile
Joined: Mar 2012
Posts: 69

View Profile WWW Email
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.
Logged
Offline (Unknown gender) Darkstar2
Reply #7 Posted on: May 15, 2014, 06:11:57 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
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.



Logged
Offline (Male) Benxamix2
Reply #8 Posted on: May 15, 2014, 07:31:09 PM

Member
Location: Chile
Joined: Mar 2012
Posts: 69

View Profile WWW Email
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.
« Last Edit: May 15, 2014, 09:20:43 PM by Benxamix2 » Logged
Offline (Male) Josh @ Dreamland
Reply #9 Posted on: May 17, 2014, 09:09:03 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
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?
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) Benxamix2
Reply #10 Posted on: May 17, 2014, 07:57:50 PM

Member
Location: Chile
Joined: Mar 2012
Posts: 69

View Profile WWW Email
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!
Logged
Offline (Male) Josh @ Dreamland
Reply #11 Posted on: May 18, 2014, 09:35:23 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
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.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1
  Print