Global variables not updating

I’m currently working on a sketch to look for received numbers (1-10) that will execute playback of various “scenes” based on their respective and corresponding data that is saved on the receiver. The playback needs to be in chronological order. I’m very new at code and I’ve gotten some amazing help around here and was able to piece together a code that works pretty well. My only issue is that my global variable newScene is not updating with any of my code apparently, so when it comes time for the program to loop, the entire sketch restarts and I start receiving signal 1 again.

Please excuse my amateur code lol

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <nRF24L01.h>

long Scene[] = {0,1,2,3,4,5,6,7,8,9,10};
// Default scene (set at 0 to start hayride at scene 1)
long originScene = 0;

// Scene counter setup
long newScene;

// Latest scene setup
long currentScene;

// scene timeout code
unsigned long curMillis;  
unsigned long receivedMillis;
unsigned long timeoutMillis = 10000;  //TIMEOUT PERIOD SETUP

// nRF24L01(+) radio attached using Getting Started board 
RF24 radio(9,10);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0;

// Address of the other node
const uint16_t other_node = 1;

// Structure of our payload
struct payload_t
{
  unsigned long ms;
  unsigned long counter;
};

void setup(void)
{
  Serial.begin(57600);
  Serial.println();
  Serial.println("Onboard Receiver Activated & Ready");
  delay(2000);
 
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

void loop(void)
{
  // Pump the network regularly
  network.update();
  
  curMillis = millis();
    
  // Is there a scene within range transmitting?
  if(network.available()) {
    // If so, grab scene data and execute
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload)); //Receive all available scenes within range
    receivedMillis = curMillis;
    if(payload.ms == originScene + 1 && currentScene != originScene + 1){  //What happens if payload is first scene? ???
    Serial.println("Executed new scene #1"); //EXECUTE SCENE 1
      currentScene = payload.ms;
      newScene = 2;
      delay(5000);
    } 
    if(payload.ms == newScene){
      currentScene = payload.ms;
        Serial.print("Executed new scene #");  //EXECUTE CURRENT SCENE
        Serial.println(currentScene);
      newScene = originScene + currentScene + 1; // Calculate which scene will come next
        Serial.print("  -  Next scene: #");
        Serial.print(newScene);
        Serial.println();
      delay(5000); //WAIT UNTIL NEXT STEP
    }
    else {
      //keep looking
    }
  }
    // Timeout if nothing received in timeout period
  else if(curMillis - receivedMillis >= timeoutMillis){
      Serial.print("Timeout");
    // EXECUTE BACKUP SCENE
      Serial.println("Auto advance to scene #");
      Serial.print(newScene);  /// What if its the first scene??
      delay(5000); 
  }
}

Does your code enters the IF statements ? Have you checked that?
Also i noticed that the second IF statement is inside the first IF statement, is that on purpose ?

if(network.available()) {
    // If so, grab scene data and execute  //////// FIRST IF STATEMENT
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload)); //Receive all available scenes within range
    receivedMillis = curMillis;
    if(payload.ms == originScene + 1 && currentScene != originScene + 1){  //What happens if payload is first scene? ???
    Serial.println("Executed new scene #1"); //EXECUTE SCENE 1
      currentScene = payload.ms;
      newScene = 2;
      delay(5000);
    } 
    if(payload.ms == newScene){  ///////////// SECOND IF STATEMENT
      currentScene = payload.ms;
        Serial.print("Executed new scene #");  //EXECUTE CURRENT SCENE
        Serial.println(currentScene);
      newScene = originScene + currentScene + 1; // Calculate which scene will come next
        Serial.print("  -  Next scene: #");
        Serial.print(newScene);
        Serial.println();
      delay(5000); //WAIT UNTIL NEXT STEP
    }/////////////////  SECOND IF CLOSING BRACKET
    else {
      //keep looking
    }
  } //////// FIRST IF CLOSING BRACKET

The reason for the nested if statements were because I was looking to have a constant else statement that would check the receive times for a timeout if there was nothing new after a certain time. In essence my train of thought was that I could loop every time I am looking for something new - remembering the previous number received and knowing what to look for next via the global variables - and with each loop I could fall into a time out and auto advance in the event a specific scene failed to broadcast/be received.

I guess there is a problem with your if statements , that's why your variable is not updated.. So make some tests and make sure the code enters the if statements as it should !!!!

Ive tinkered with the IFs and it still seems to be an issue not rolling over the info.

/*
 CORNER OF CHAOS
 Hayride Automation Control System (HACS) v1.0 2014
 Wireless show control comunications between hayride wagon 
 and individual scenes.  Wagon receives scene numebers sent
 from scene nodes and cues playback of scenes in 
 chronological order
 
 RECEIVE NODE - use for wagons
*/

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <nRF24L01.h>

long Scene[] = {0,1,2,3,4,5,6,7,8,9,10};
// Default scene (set at 0 to start hayride at scene 1)
long originScene = 0;

// Scene counter setup
long newScene;
unsigned long thisReceived;

// Latest scene setup
long currentScene;

// scene timeout code
unsigned long curMillis;  
unsigned long receivedMillis;
unsigned long timeoutMillis = 10000;  //TIMEOUT PERIOD SETUP

// nRF24L01(+) radio attached using Getting Started board 
RF24 radio(9,10);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0;

// Address of the other node
const uint16_t other_node = 1;

// Structure of our payload
struct payload_t
{
  unsigned long ms;
  unsigned long counter;
};

void setup(void)
{
  Serial.begin(57600);
  Serial.println();
  Serial.println("Onboard Receiver Activated & Ready");
  delay(2000);
 
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

void loop(void)
{
  // Pump the network regularly
  network.update();
  
  curMillis = millis();
    
  // Is there a scene within range transmitting?
  if(network.available()) {
    // If so, grab scene data and execute
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload)); //Receive all available scenes within range
    receivedMillis = curMillis;
    thisReceived = payload.ms;
  }
    // Timeout if nothing received in timeout period
  else if(curMillis - receivedMillis >= timeoutMillis){
      Serial.print("Timeout");
    // EXECUTE BACKUP SCENE
      Serial.println("Auto advance to scene #");
      Serial.print(newScene);  /// What if its the first scene??
      delay(5000); 
  }
  if(thisReceived == originScene + 1 && currentScene != originScene + 1){  //What happens if payload is first scene? ???
      Serial.println("Executed new scene #1"); //EXECUTE SCENE 1
    currentScene = thisReceived;
    newScene = 2;
    delay(5000);
  } 
  if(thisReceived == newScene){
      currentScene = thisReceived;
        Serial.print("Executed new scene #");  //EXECUTE CURRENT SCENE
        Serial.println(currentScene);
      newScene = originScene + currentScene + 1; // Calculate which scene will come next
        Serial.print("  -  Next scene: #");
        Serial.print(newScene);
        Serial.println();
      delay(5000); //WAIT UNTIL NEXT STEP
  }
  else {
    //keep looking
  }
}

I think you should only process the received message when you actually receive it, i.e. inside the if(network.available()) block.

I suggest you separate out the code dealing with network reception with the logic handling scene numbers. You could do that by writing a function to handle a received scene number and calling that with the received scene number as an argument each time you receive a new scene number.

The timeout logic should be simple enough to implement but it would be sensible to leave that out until you have got the basic logic to handle a sequence of scene numbers working correctly.

Make sure your sketch prints out trace messages to show what it has received and what it is doing to the scene number as a result, so that you can check whether it's working correctly.