Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FanOfHumor on Fri 29/07/2022 23:19:58

Title: (Solved)Addtoglobal integer array through repeating function not in room script.
Post by: FanOfHumor on Fri 29/07/2022 23:19:58
I have this global integer array  that I want to add to each always but whenever I place this in any other repeatedly execute that is not in a room it doesn't do anything.I have tried putting it in a script at the top of the script list.
    timer[0]+=1;
  timer[1]+=1;
  timer[2]+=1;
  timer[3]+=1;
  timer[4]+=1;
  timer[5]+=1;
  timer[6]+=1;
  timer[7]+=1;
  timer[8]+=1;
  timer[9]+=1;
Title: Re: Add to global integer array through repeating function not in room script.
Post by: Khris on Wed 03/08/2022 09:40:07
Open the global script and look for the existing
Code (ags) Select
function repeatedly_execute() {
  // code in here
  // ...
}


Now put this inside:
Code (ags) Select
  for (int i = 0; i < 10; i++) timer[i]++;
Title: Re: Add to global integer array through repeating function not in room script.
Post by: FanOfHumor on Fri 05/08/2022 15:56:17
That didn't work.Are you sure you understood my post entirely.I am wondering if this is maybe an error with ags because I have not had this problem before 3.6.0.I have had many other problems with global integers not being recognized as changed even when they are in the top of a script list.So to put it simply:I have a script at the top of the list and in that I have repeatedly execute always copied from global script and global integers in there adding up every game loop.I'm sure that they are adding up because I had it display the integer by placing Display() right next to the adding integer and it did show to be adding up .But if I place Display in a room script and try to display the integer from there nothing happens.The integer stays the same.I hope i've made this clearly understood.

This displays the global integers value.
Code (ags) Select

// new module script
function repeatedly_execute_always()
{
  test+=1;
  String s=String.Format("%d",test);
  Display(s);
}
// new module header
int test;

If the above script doesn't have display this in room script doesn't display integer.It always displays zero.
Code (ags) Select

function room_RepExec()
{

 
  String s=String.Format("%d",test);
  Display(s);
}

Title: Re: Add to global integer array through repeating function not in room script.
Post by: Crimson Wizard on Fri 05/08/2022 17:53:25
Quote from: FanOfHumor on Fri 05/08/2022 15:56:17I have a script at the top of the list and in that I have repeatedly execute always copied from global script and global integers in there adding up every game loop.I'm sure that they are adding up because I had it display the integer by placing Display() right next to the adding integer and it did show to be adding up .But if I place Display in a room script and try to display the integer from there nothing happens.The integer stays the same.

This sounds like a variable duplication case, as explained in this article:
https://adventuregamestudio.github.io/ags-manual/TheScriptHeader.html

Please tell how did you declare these variables? Do you use "Global Variables" planel, or declare them yourself in the script header; if you do this yourself then do you use import/export, or just put them in the header?
Title: Re: Add to global integer array through repeating function not in room script.
Post by: FanOfHumor on Sat 06/08/2022 04:44:28
I just put them in the header as this exactly without import or export.

int timer[10];

Is there something wrong with doing it like this?

EDIT:ok I just read the link you showed me and I understand that I was doing it wrong.Thanks again.
Title: Re: Add to global integer array through repeating function not in room script.
Post by: FanOfHumor on Sat 06/08/2022 04:55:55
I don't understand how to export a variable to all room scripts.
Title: Re: Add to global integer array through repeating function not in room script.
Post by: Crimson Wizard on Sat 06/08/2022 05:17:11
Quote from: FanOfHumor on Sat 06/08/2022 04:55:55
I don't understand how to export a variable to all room scripts.

Here's the page which explains how to import/export variables:
https://github.com/adventuregamestudio/ags-manual/wiki/ImportingFunctionsAndVariables

In short:
Code (ags) Select

// in script module's header
import int timer[10];

// in script module's body
int timer[10];
export timer;