There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: (Solved)Addtoglobal integer array through repeating function not in room script.  (Read 267 times)

FanOfHumor

  • You rock!I'm your biggest fan!
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;
« Last Edit: 06 Aug 2022, 21:08 by FanOfHumor »

Open the global script and look for the existing
Code: Adventure Game Studio
  1. function repeatedly_execute() {
  2.   // code in here
  3.   // ...
  4. }

Now put this inside:
Code: Adventure Game Studio
  1.   for (int i = 0; i < 10; i++) timer[i]++;

FanOfHumor

  • You rock!I'm your biggest fan!
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: Adventure Game Studio
  1. // new module script
  2. function repeatedly_execute_always()
  3. {
  4.   test+=1;
  5.   String s=String.Format("%d",test);
  6.   Display(s);
  7. }
  8. // new module header
  9. int test;
  10.  
If the above script doesn't have display this in room script doesn't display integer.It always displays zero.
Code: Adventure Game Studio
  1. function room_RepExec()
  2. {
  3.  
  4.  
  5.   String s=String.Format("%d",test);
  6.   Display(s);
  7. }
  8.  
« Last Edit: 05 Aug 2022, 16:06 by FanOfHumor »

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.

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?
« Last Edit: 05 Aug 2022, 17:55 by Crimson Wizard »

FanOfHumor

  • You rock!I'm your biggest fan!
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.
« Last Edit: 06 Aug 2022, 04:47 by FanOfHumor »

FanOfHumor

  • You rock!I'm your biggest fan!
I don't understand how to export a variable to all room scripts.

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: Adventure Game Studio
  1. // in script module's header
  2. import int timer[10];
  3.  
  4. // in script module's body
  5. int timer[10];
  6. export timer;
  7.  
« Last Edit: 06 Aug 2022, 06:09 by Crimson Wizard »