Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ty3194 on Tue 24/07/2012 03:51:13

Title: [SOLVED] Scripting problems with in-game drug use
Post by: ty3194 on Tue 24/07/2012 03:51:13
I'm having trouble finding a way to slow down/speed up time when using certain drugs. My game has a clock GUI binded to global scripting which uses variables to change time based on default game FPS. When the user drinks cough syrup, 1 is added to a variable vDXM2, and after some time passes to allow for onset, vDXM2's value is sent to a variable named vDXM, which will have all the drugs effects once scripted in. Here is the code:

Code (AGS) Select

function repeatedly_execute_always() {
 

// CLOCK

if (gPause.Visible) return;

    if (IsTimerExpired(1)) {
    vDXM = vDXM2; vDXM2 = 0;
    Display("You start feeling the DXM");
    }
   

  // advance game clock
  time_loop++;
  if (time_loop == 40) { // advance game minutes
    time_loop = 0;
    time_min++;

    if (time_min == 60) { // advance game hours
      time_min = 0;
      time_hour++;
    if (vDXM > 0) {
      vDXM -= 1;
      }
     
      if (time_hour == 24) { // advance game days
        time_hour = 0;
        time_day++;
      }
    }
  }


  // update clock label
  if (time_hour < 12) {
    if (time_hour == 0)  lblClock.Text = String.Format("12:%02d a.m.", time_min);
    else lblClock.Text = String.Format("%02d:%02d a.m.", time_hour, time_min);
  }
  else lblClock.Text = String.Format("%02d:%02d p.m.", time_hour-12, time_min);
 

 
 

// DRUG EFFECTS

lblDrug1.Text = String.Format ("DXM %d", vDXM);
lblDrug2.Text = String.Format ("DXM2 %d", vDXM2);

//DXM

if (vDXM > 1) {
}
 




My question is how should I go about slowing time once enough DXM has been used (say if vDXM > 1)? Should I temporarily increase framerate per second or temporarily change the clock so that 40 frames = one half or a fourth of a second versus one, and how?

Also, after an hour passes I want the drugs effects (vDXM) to decrease by a certain amount. At the moment it decreases by 1, but is there a way to decrease by a half or a fourth? When I tried using 0.5 the output window says:
QuoteGlobalScript.asc(94): Error (line 94): Type mismatch: cannot convert 'float' to 'int'
and when I tried using 1/2 my gDrugs GUI (which displays vDXM value) doesn't decrease even after waiting several minutes, meaning -= 1/2 has no effect.

Code (AGS) Select

if (time_min == 60) { // advance game hours
      time_min = 0;
      time_hour++;
    if (vDXM > 0) {
      vDXM -= 1;
      }

Thanks in advance!
Title: Re: Scripting problems with in-game drug use
Post by: Khris on Tue 24/07/2012 09:08:58
1/2 isn't treated as number but as instruction; the result is 0 since int values are always rounded down.
To be able to use fractions, you need a float:
Code (ags) Select
float vDXM = 1.5;

Now, regarding the passage of time, wouldn't it make more sense if the entire game is slower/faster (as opposed to only the clock speed)? Because since you're already using the game's FPS to advance the clock, all you need to do is change the game's speed to affect everything else. Also, that way, the person playing the game is directly exposed to the different senses of time.
Look up SetGameSpeed().
Title: Re: Scripting problems with in-game drug use
Post by: ty3194 on Tue 24/07/2012 10:33:56
Thanks Khris! I looked up SetGameSpeed() and realized I could add that to my vDXM variable's effects section in the globalscript, and once a certain value is reached (in this case vDXM > 5), I SetGameSpeed() to 20, which is half the normal value. This also effectively halves the rate at which times progresses -- and thus doubles the time it takes for the clock to tick -- thereby ultimately increasing the time it takes vDXM to reduce to 0 (AKA the half-life of the drug). I no longer need to use floats, this worked great! Thanks again.
Title: Re: [SOLVED] Scripting problems with in-game drug use
Post by: Khris on Tue 24/07/2012 11:42:40
Good, but why don't you use a direct relationship?
The numbers are all there, why not use something like:
Code (ags) Select
  SetGameSpeed(40 - vDXM * 2);
whenever vDXM changes?

That way, vDXM = 0 has no effect, and vDXM = 10 slows the game down to half the original speed, but with a smooth transition.
Title: Re: [SOLVED] Scripting problems with in-game drug use
Post by: ty3194 on Wed 25/07/2012 09:43:44
Thanks for the advice. I tried getting that to work and couldn't very easily. My current system works just fine though. Thanks