• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [Solved]Timeline not running

L

Luxxum

Guest
I'm trying to set up some code so that if the player character dashes (simple x=x+var currently) they must wait a certain amount of time before dashing again, with the potential to upgrade to multiple dash "charges" later on. I don't want to use alarms because I am told you can only have 12 of them at any given time, so I am trying to use timelines. However, I can't seem to get it to work. The script containing the code to create the timeline is definitely running, but the timeline isn't being created or isn't working how it should. I think it might have to do with me trying to use a variable for the name, but am unsure.

Here is what I have:
----------------------------------------------------------------------------------------------------------------
if timeline_exists(dsh_script_count) //to stop weird code for multiple dashes
{
dsh_script_count = dsh_script_count + 1
}


dsh_script_count = timeline_add()
timeline_moment_add_script(dsh_script_count, 0, dash_timer_animation_script)
timeline_moment_add_script(dsh_script_count, dsh_timer, dash_add_script)
timeline_moment_add_script(dsh_script_count, dsh_timer+1,end_dash_timeline_script)

timeline_index = dsh_script_count
timeline_position = 0
timeline_running = true
timeline_loop = false



------------------------------------------------------------------------------------------------------------------
dash_timer_animation_script:
------------------------------------------------------------------------------------------------------
dshvar = dsh_script_count //so if another timeline is created while this one is running, this timeline can still delete itself



//add animation for dash timer here




------------------------------------------------------------------------------------------------------------------
dash_add_script:
------------------------------------------------------------------------------------------------------
dshst = dshst + 1 //a "charge" of dshst is consumed for each dash, so this restores it





------------------------------------------------------------------------------------------------------------------
end_dash_timeline_script
------------------------------------------------------------------------------------------------------
timeline_delete(dshvar)


------------------------------------------------------------------------------------------------------------------



Any idea what might be going on?
 
That's not 12 alarms in your entire game.....that's per instance, and I think it's actually 16 alarms. Regardless - the limit is not 12 in the entire game!

You can do something like this:

create event:
Code:
dash=false;
step_event
Code:
if !dash
  {
  if keyboard_check_pressed(vk_space)
      {do dash etc;
      alarm[0]=100;
      dash=true;
      }
  }
alarm[0]:
Code:
dash=false;
In the code above it sets a variable 'dash' to false in the create event.

During a step event it checks if 'dash' is false (shown by the variable name being preceded by an exclamation mark). If it is, and the space key is pressed, then it executes a piece of code (whatever you want to do for the dash move) and sets alarm 0 to 100. Then it sets 'dash' to true - meaning that even if you pressed space again nothing would happen. As the piece of code it is in is dependent on 'dash' being false - which it now isn't.

The alarm sets 'dash' to false when it runs down.

Now if you pressed space it would do dash again, as the variable has been reset to equal false.
 
L

Luxxum

Guest
That's not 12 alarms in your entire game.....that's per instance, and I think it's actually 16 alarms. Regardless - the limit is not 12 in the entire game!

You can do something like this:

create event:
Code:
dash=false;
step_event
Code:
if !dash
  {
  if keyboard_check_pressed(vk_space)
      {do dash etc;
      alarm[0]=100;
      dash=true;
      }
  }
alarm[0]:
Code:
dash=false;
In the code above it sets a variable 'dash' to false in the create event.

During a step event it checks if 'dash' is false (shown by the variable name being preceded by an exclamation mark). If it is, and the space key is pressed, then it executes a piece of code (whatever you want to do for the dash move) and sets alarm 0 to 100. Then it sets 'dash' to true - meaning that even if you pressed space again nothing would happen. As the piece of code it is in is dependent on 'dash' being false - which it now isn't.

The alarm sets 'dash' to false when it runs down.

Now if you pressed space it would do dash again, as the variable has been reset to equal false.
oh, ok, thanks! By any chance, do you know what might be wrong with my code? even if I'm not using it I'd like to know what's wrong
 
Um....sometimes people's code seems a bit strange to me, but at a guess.....

You have a timeline name 'dsh_script_count', and then are trying to treat it like a variable when you have:
Code:
dsh_script_count=dsh_script_count+1;
Presumably you hope this creates a new timeline by creating a name 'dsh_script_count1'? and that if you repeat it again it will make 'dsh_script_count2', and so on.....Or that the asset type, and it's number, that 'dsh_script_count' is connected to will be advanced by 1, and thus create a new asset?

But variables don't quite work like that when it comes to creating assets. It would take a better GM user than me to explain what you can, and can't do - and why that is the case. That's assuming I'm even understanding your intentions correctly in the first place, and am not talking out of my backside about how you can create assets (which is a distinct possibility!)

Even if you did it like this:
Code:
count=0;
repeat (5)
{dsh_script_count="dsh_script_count" + string(count);
dsh_script_count = timeline_add()
count+=1;}
You could draw the variable 'dsh_script_count' and it would show "dsh_script_count5". As it's setting "dsh_script_count" as a piece of text, and then putting the value of 'count' on at the end as a string. It would repeat this five times, so that it finally shows dsh_script_count5.

But it wouldn't create 5 timelines called dsh_script_count0 / dsh_script_count1/ dsh_script_count2 and so on. Once you get to that final 'dsh_script_count=timeline_add()' it doesn't matter what "value" you've given to the variable, as it is then assigned specific details by tying it into a timeline asset.

This is I do know for a fact, as I just tried it - the only asset that actually existed was a timeline accessed through the variable 'dsh_script_count'
 
Top