Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TheVolumeRemote on Wed 19/05/2021 19:08:17

Title: [SOLVED] Using GetGameSpeed to return to players speed selection
Post by: TheVolumeRemote on Wed 19/05/2021 19:08:17
Hey mates, hope you all are well!

What I'm trying to do is get the players current game speed, store it as a variable and use it to return the game to the speed the player had previously selected, after an animation- because- I'm slowing the game down to default (40) before most animations.

What I tried that isn't working is this

Code (ags) Select
//created global variable "PrevSpeed" (int)
//In room script under interact function for animation

PrevSpeed = GetGameSpeed();
SetGameSpeed(40);
oObject.Animate(0, 0, eOnce, eBlock, eForwards);
SetGameSpeed(PrevSpeed);


I had used something similar to return the player to the previous room and location (if they cancel out of using the map by pressing Return) and it worked so I thought this would but alas.
Thanks for any tips  :)

EDIT: the above example works, I had another setgamespeed set in the room script that I had missed (whoopsie). If you searched your way here for help, using the above example will work :)
Title: Re: Using GetGameSpeed to return to players speed selection
Post by: eri0o on Wed 19/05/2021 19:57:05
What part isn't working?
Title: Re: Using GetGameSpeed to return to players speed selection
Post by: TheVolumeRemote on Wed 19/05/2021 20:52:11
Apologies, it is working. I had a rogue setgamespeed in the room script that I didnt see and forgot about. I feel shame.

Thanks for the help though!
Title: Re: [SOLVED] Using GetGameSpeed to return to players speed selection
Post by: Cassiebsg on Wed 19/05/2021 23:14:21
I suggest you create a custom pointer function to animate your objects that need the game speed slowed down.

Since it would be much easier for you to write the function once, and then just type MyAnimation(oObject);, than having to type all those lines everytime you want to animate an object.  ;)
Title: Re: [SOLVED] Using GetGameSpeed to return to players speed selection
Post by: Khris on Thu 20/05/2021 08:59:28
Why are you allowing the player to change the game speed in the first place? Maybe there's a different solution that doesn't require changing the speed?
Is this about the character's walking speed?

Anyway, you can do this:
Code (ags) Select
//header
import void AnimateS(this  Object*, int loop, int delay, Direction dir);

// top of main script
void AnimateS(this  Object*, int loop, int delay, Direction dir) {
  PrevSpeed = GetGameSpeed();
  SetGameSpeed(40);
  this.Animate(loop, delay, eOnce, eBlock, dir); // eBlock is a given, therefore so is eOnce
  SetGameSpeed(PrevSpeed);
}


Now you can do
Code (ags) Select
  oObject.AnimateS(0, 0, eForwards);