(Solved)Addtoglobal integer array through repeating function not in room script.

Started by FanOfHumor, Fri 29/07/2022 23:19:58

Previous topic - Next topic

FanOfHumor

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;

Khris

Open the global script and look for the existing
Code: ags
function repeatedly_execute() {
  // code in here
  // ...
}


Now put this inside:
Code: ags
  for (int i = 0; i < 10; i++) timer[i]++;

FanOfHumor

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

// 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

function room_RepExec()
{

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


Crimson Wizard

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?

FanOfHumor

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.

FanOfHumor

I don't understand how to export a variable to all room scripts.

Crimson Wizard

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

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

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

SMF spam blocked by CleanTalk