Jump to content


Photo

passing object id through multiple objects


  • Please log in to reply
4 replies to this topic

#1 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 11 May 2012 - 08:50 AM

the main character in my game has a variable set in create called var_creator set to self.id and when you press f1 it creates obj_inventory and gives that object the main character id, now heres where it goes wrong.... that inventory is then SUPPOSED to create several buttons and pass that id to the buttons (so the buttons can determine whether the main character has enough stat points to add a point to a stat.) and in debug mode i can tell that the character id gets passed to the inventory but never passes to the buttons.
so as a result the buttons dont react or draw properly. the code is thus:
//in the character main character create/
var_creator=self.id

//in the f1 event/
var_myinventory = instance_create(view_xview[2]+512,view_xview[2]+400,obj_inventory)
var_myinventory.var_creator = var_creator//this part all works/

//in the create event of obj_inventory/
var_buttonid1 = instance_create(view_xview[2]+165,view_yview[2]+315,obj_endobutton)
var_buttonid1.var_creator = var_creator
//at this point obj_endobutton is created but obj_endobutton.var_creator = 0 instead of inheriting the id from obj_inventory/
ive tried several variations (im pretty new to code) ...anyway im struggling here, an i cant seem to get it on my own. maybe some advice? thanks.

Edited by Piwaket, 11 May 2012 - 10:26 AM.

  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 11 May 2012 - 09:01 AM

i dont see any spelling mistakes(but i may be blind) try adding ";" at the end of the lines(probably wont fix it)

If you dont find the problem, then test the value of var_creator just after you created the inventory(before buttons) and see if its correct.

otherwise use a with statement instead of the "object." bit

with(instance_create(view_xview[2]+165,view_yview[2]+315,obj_endobutton))
{
var_creator = other.var_creator;
}
  • 0

#3 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 11 May 2012 - 09:19 AM

the inventory is created with the proper id sent to it
the inventory creates the buttons as soon as it is created....
i tried the with statement instead with no better results. obj_inventory.var_creator returns:10135 and obj_endobutton.var_creator returns: 0

but instance_number(endobutton) returns: 1 so it IS there.....

i dont get it.... ive been over an over the spelling... and all the objects involved.... im really tired as a result and thats probably not helping..... :D

Edit: as a stupid solution i gave it a collision event with my inventory that gave it the inventory's creator id but i'd really like it to send the id properly in creation.

Edited by Piwaket, 11 May 2012 - 09:33 AM.

  • 0

#4 troido

troido

    GMC Member

  • GMC Member
  • 150 posts
  • Version:GM8

Posted 11 May 2012 - 10:01 AM

when you create an instance, first the create event of that object is executed, and then the code resumes.
to solve this problem, you could try to make a with statement in the f1 event, and put all code from the create event of obj_endobutton in that with statement.
that would look like this:
var_myinventory = instance_create(view_xview[2]+512,view_xview[
2]+400,obj_inventory)
with var_myinventory{
// all code in the create event of obj_endobutton
}

  • 0

#5 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 11 May 2012 - 10:25 AM

when you create an instance, first the create event of that object is executed, and then the code resumes.
to solve this problem, you could try to make a with statement in the f1 event, and put all code from the create event of obj_endobutton in that with statement.
that would look like this:

var_myinventory = instance_create(view_xview[2]+512,view_xview[
2]+400,obj_inventory)
with var_myinventory{
// all code in the create event of obj_endobutton
}


omg my savior! why .....whyyy didnt i think of trying that.... works just like i want now thank you thank you thank you thank you!!!!!!!!!!!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users