SOLVED: Do once only: Reset Room

Started by Slasher, Sat 02/11/2013 10:21:11

Previous topic - Next topic

Slasher

Hi,

I have just discovered an issue that must be sorted.

It appears that Reset Room does not reset Do once only.

When going back into the Reset Room certain things do not run.

Shoot an object = do once only = turn to fire =  score points just once.

Re entering the room the object fails to react at all.

QuoteResetRoom from Manual:
QuoteDiscards all the data that the engine has in memory about when the player last visited ROOM_NUMBER, and resets it as if they'd never been there. The next time the player goes to that room, all the objects and scripts will be in their initial state (as set up in the editor), and not how they were when the player left the room. The "First time enters room" event will be run when they enter this room again.

Can you help with this please....


selmiak

So do once only does excatly what it says it does! Just use a bool hasfiredthistime and set it to false in First time enters room.

Khris

Yeah, AGS doesn't know that DoOnceOnly belongs to a certain room; it's a global command, like timers. Doesn't matter that you used it in room script X, it's not part of the room's data.

Here's how you implement selmiak's suggestion:

Code: ags
// top of room script
bool someGameState;  // default value: false

  // where you used to use if (Game.DoOnceOnly("...")) { ... }:
  if (someGameState == false) {
    someGameState = true;
    // the following is executed one time only, until someGameState is reset to false
    ...
    ...
  }

  // right before/after calling ResetRoom():
  someGameState = false;  // reset value

Crimson Wizard

It is not occasional that DoOnceOnly is called as "Game.DoOnceOnly", and not "Room.DoOnceOnly" :).

Slasher

Hi,

thanks guys.

Is this correct?

Code: ags

 //SHOOT CRAFT 1
  
  if(cmiss.PPCollidesWithO(ocraft1)&& cmiss.Transparency==0 && someGameState == false) {
  if (Game.DoOnceOnly("Craft1 destroyed")) 
  if (someGameState == false) {
    someGameState = true;
    aBang.Play();
    ocraft1.SetView(113, 3, 0);
    ocraft1.Animate(3, 4, eRepeat, eNoBlock); 
    cmiss.Transparency=100;
    Points=(Points +100);
  }
  }  


Then in the next room after the Room is reset:
Code: ags
}
 else if (cSpaceman.PreviousRoom==29 && Lose_Game==true && Lost==1) {
 
  someGameState=false; 
  ResetRoom(29);
}
  


I have implemented bool someGameState=false at the top of Room script.



Khris

No, not at all. You have to use it instead of DoOnceOnly, like I plainly mentioned (and which is the entire point of this thread).
Code: ags
  if(cmiss.PPCollidesWithO(ocraft1)&& cmiss.Transparency == 0 && craft1Destroyed == false) {
    craft1Destroyed = true;
    aBang.Play();
    ocraft1.SetView(113, 3, 0);
    ocraft1.Animate(3, 4, eRepeat, eNoBlock);
    cmiss.Transparency = 100;
    Points += 100;
  }

Note that you can arbitrarily rename variables (as long as you follow naming conventions), which is why I used craft1Destroyed instead of someGameState, which was not supposed to be used literally.

Slasher

#6
Hi,

Thanks guys and especially to Khris for his piece of informal information and script.

It works like a dream and now I know (I should have realized) about Resetting Rooms along with Do Once Only.

I had to implement the script for over 30 objects along with a couple of other issues.

This rocket is 'up up and away', as they say.... (laugh)

cheers for help

slasher



SMF spam blocked by CleanTalk