Pages: « 1 2
  Print  
Author Topic: Not able to set or get userdefined variables with unique values for instances.  (Read 3998 times)
Offline (Unknown gender) intygamer
Reply #15 Posted on: April 27, 2014, 09:36:44 PM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
Quote
if I have to access it outside the object that created it I would add prefix object_name.instance_id.variable?
You never add object_name. Instance_id is unique to each instance no matter what object they are. So instance_id.variable will work. object_name usually returns the oldest existing instance, so object_name.instance_id.variable would be like id.someotherid.variable, which is pretty much undefined.

Can you maybe post an example? I just tried adding instances to lists and changing them and it works fine for me.
Try this: https://www.dropbox.com/s/oaiuuppj2htmvnw/unit_test.gmk

obj_unit.un.x I only used this in draw event for obj_text before the modification I made in the attached file.  It would only show 0's for defined variable with un.x.  Prefixing un with the object_name fixed that.  Objects are not global.

I tried to modify old code to make it work with out object_name.id.variable.
Code: [Select]
with (ds_list_find_value(t0_list,obj_unit.up))
{
draw_text(10,50,x);
draw_text(10,70,y);
draw_text(10,90,image_blend);
draw_text(10,110,team);
draw_text(10,130,max_moves);
draw_text(10,150,ap);
draw_text(10,170,hp);
}

Thanks TheExDeus for that example.  I have attach an example for you.  I have modified it using controller object to create instances of obj_unit, like you have in your example.  Now I can see the userdefined values of the last instance with draw event instead of zero.  I still have the same problem, that only value for max_moves is coming from last instance created.

I the example arrow keys move units, pageup and pagedown key cycle threw units, and space bar resets moves back to zero.

Thanks
Joe
   
« Last Edit: April 29, 2014, 07:50:36 PM by intygamer » Logged
Offline (Unknown gender) intygamer
Reply #16 Posted on: May 01, 2014, 06:43:21 PM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
TheExDeus,
Not sure if file attachment works, can't see it when not logged in, so I added a link.  Let me know if you need it in different format.  This is the example you requested.

http://www.mediafire.com/download/fqryepq1knpmjwa/SwitchInstanceUserVariables.gm81

Thanks
Joe
Logged
Offline (Unknown gender) TheExDeus
Reply #17 Posted on: May 02, 2014, 10:36:49 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
The bug is that you need to define the same variables in unit's create event as well. Like add these to obj_unit create:
Code: [Select]
team = -1;
max_moves = -1;
ap = -1;
hp = -1;
They can have any value as you will override them in obj_controller. I like to set them to undefined value like -1 so in debug I could find bugs easier.
I guess this is another parser bug as we technically support "Init undefined variables to 0". I think the parser cannot figure out if the variables are defined. In GM you probably would get the "Undefined variable" error. It trows the same error in ENIGMA as well. You should define variables before using them.
« Last Edit: May 02, 2014, 10:40:03 AM by TheExDeus » Logged
Offline (Unknown gender) intygamer
Reply #18 Posted on: May 02, 2014, 02:14:45 PM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
The bug is that you need to define the same variables in unit's create event as well. Like add these to obj_unit create:
Code: [Select]
team = -1;
max_moves = -1;
ap = -1;
hp = -1;
I declared the variables like you said and now the userdefined variables work.   (Y)

Thank you very much!  :)
And thanks to everyone that helped.
Joe
Logged
Offline (Male) Goombert
Reply #19 Posted on: May 03, 2014, 01:30:15 PM

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

View Profile
Josh will fix these issues with his new compiler.
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.

Pages: « 1 2
  Print