I'm stuck with a big problem about Timeline and inhéritance.
Here's a simple exemple of what I want to do.
TimelineAndInheritanceProblem GM81 version
TimelineAndInheritanceProblem GMK version (using this converter : GM[81]Converter as I haven't GM8.0 anymore)
I was certain that it would work the way I code it, but it doesn't ...
Using Game Maker 8.1 !
I have a system object, running a timeline for a parent object (with a with statement, for avoiding the child object inherit it).
I've wrote a script for using in moment of the timeline, in order to spawn child object. So at moment 60 and 120 of the timeline, the script is launched.
here is the flow and the problem:
1) Timeline for Parent object is running
2) Moment 60 : Spawn script is launch. It set some Parent object's variables and create an instance of Child object.
3) As Child object is child's Parent object, in its Create Event, it get the same variable value than its parent but it doesn't.
4) Moment 120 : Spawn script is launche again, change Parent's variable and create another instance of Child object
5) Child object is created, but doesn't have the new value of its parent's variables too. Variables are inherited, but not their values, wich remain those declared first in the parent's create event.
BUT parent's variable ARE modified by the Spawn script at moment 60 and 120 ...
Spawn Script (launch in moment's timeline for Parent object.
Spawn(childObject, spriteType)
question = argument1 //set a valu for the sprite
switch(question) //test it.
{
case 1 : sprite = spriteA; break; //If 1, store spriteA in sprite
case 2 : sprite = spriteA; break; //If 2, store spriteB in sprite
}
nb += 1//increment the object array of 1
object[nb] = instance_create(x,y,argument0) //create the child objet (ex : child) in the array set by nb variable.
In the System Object
with(parent){
timeline_index = timeline0
timeline_running = true
}
In the parent object
CREATE EVENT
question = 0 //determine type of sprite spriteA = sprite0 spriteB = sprite1 sprite = 0 //use to store the sprite nb = 0 //use to increment object[0] object[nb] = 0 //Sotre the ID of the created child
In the Child Object
CREATE EVENT
event_inherited() //Get parent's variable /** variables below are just here to use event_inherited, as I will in my game**/ hit = 0 hitNb = 0
DRAW EVENT
draw_sprite(sprite,0,x,y)//draw the sprite stored in the sprite variable.
STEP EVENT (only for moving the child instance and see the next one)
x -= 2
Child object set its parent as Parent Object in its Option windows.
I don't understand why child object doesn't get parent's variable values each time the script in the timeline is luanched and modified them. The sprite, the question variable of thoose instances remain equal to 0.
I've tried to set an alarm, to let one step between modification of the parent variable anec the creation of the child, but it doesn't work too ...
I've tried to set a draw_sprite in the draw event of parent object and inherit it by the child : Parent Object draw the new sprite, but the second child doesn't and take the default value as the first child
Any idea ? Is there something I don't get about inheritance and Timeline ?? May be a timing problem in event order ?
Edited by Yokan, 29 August 2012 - 07:53 AM.











