Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: AndreasBlack on Wed 20/04/2022 21:02:39

Title: How do i trigger a Global Timer from the Global Script (Crimson Module)
Post by: AndreasBlack on Wed 20/04/2022 21:02:39
I'm trying to make it start from the Globalscript, however i'm not sure that is the correct solution. Short explanation follows,

I have managed to get an NPC to leave a dialog to go into another room and come back in time into the same room again, thru Room scripting Timer only.
However once the playable character follows the NPC into the other room, it cancels the NPC's comeback (The Timer from the Room).


So i'd figured maybe it needs to be set from the globalscript so the Timer does not bother if the player changes the room, since it then would act "Globally"  ???
However i get no reaction at all when i try to start the timer from the global script after the Dialog occured. I'm probably doing something basic wrong, as always. (laugh)

Help is very much appreciated !

Code (ags) Select

//GlobalScript.ash

Timer *CharacterTimer;
Timer *Timers[100];



Code (ags) Select

//From the Dialog

@4
Saskia: Sure, BRB!

    cSaskia.ChangeRoom(21, 683, 143);         //Now when she enters 21, the Timer should start from the globalscript (is what i'm trying to do)                         
    Saskia_Left=true;                                   // and she should Re-visit Room 4 that she came from when the timer ends,
    Saskia_Global=1;                                   //and hopefully not be cancelled this time, unless player speaks with her, ofc,


Here's some various attempts.

Code (ags) Select


//Main Globalscript

function room_RepExec()
{
 
 
 

if (Saskia_Left==true)

{
  Display ("timer test!");
  CharacterTimer = Timer.StartRT(1.0);
 
 
}


  if(cSaskia.Room == 21)CallRoomScript(1);
{

Display ("Timer test 2");



}
 
if (Timer.IsExpired(CharacterTimer))

{
  Display ("Timer Test 3");
  cSaskia.ChangeRoom(4);
}

if (Saskia_Global==1))

{
  Display ("Timer Test 3");
  cSaskia.ChangeRoom(4);
}






Title: Re: How do i trigger a Global Timer from the Global Script (Crimson Module)
Post by: Crimson Wizard on Wed 20/04/2022 21:14:12
Following code caught my eye:
Quote from: AndreasBlack on Wed 20/04/2022 21:02:39
Code (ags) Select

//GlobalScript.ash

Timer *CharacterTimer;
Timer *Timers[100];


This is a classic mistake of placing variables in header without "import" keyword, and it makes variables to duplicate in every other script you have. Basically, you will have duplicates of variables, although with same name, in each script, and they will act separate from each other.

Correct global variable declaration
Code (ags) Select

//GlobalScript.ash

import Timer *CharacterTimer;
import Timer *Timers[100];

Code (ags) Select

//GlobalScript.asc

Timer *CharacterTimer;
Timer *Timers[100];
export CharacterTimer, Timers;


For more information please see:
https://github.com/adventuregamestudio/ags-manual/wiki/TheScriptHeader
https://github.com/adventuregamestudio/ags-manual/wiki/ImportingFunctionsAndVariables
Title: Re: How do i trigger a Global Timer from the Global Script (Crimson Module)
Post by: AndreasBlack on Wed 20/04/2022 21:46:42
Thanks Crimson! Weeeiii! It worked with Global, like i thought! Happy now!