Resetroom affects global variable changed from that room

Started by AndreasBlack, Mon 23/10/2023 15:37:42

Previous topic - Next topic

AndreasBlack

I thought to myself 'yes'! That's it! I could probably use Resetroom to do this! 'psuedo hotel room trick' = one room but stores the room changes in global variables (light,switches,etc). If i store the values in global variables those are obviously outside of the room.

However once leaving the room calling
Code: ags
 ResetRoom(number);

It takes away the added global values, since it was added in the room. If it was a room int value i would get it. Is that delibrate logic? It would make forexample "psuedo hotelroom" setups easier. If the global values would not get affected. I've solved it with a dumb solution atm using bools and a int for each room, which works since i'm no legit coder.

But it's more of a job i think. Then if i could have just went *add global variable int for each psuedo room* and ++; each time a button or a lamp or whatever is lit in that room and ofc --; when turned off then re-entering the room and it will check for if it was that room i was in before or another room and it will setup itself accordingly with that one int (if i'm thinking correctly). I understand ofc there are probably  'programmer ways' to do this properly

Code examples are very much welcomed as always! Lots of objects and hotspots to click around in the room :-D


Khris

I cannot confirm this.
ResetRoom() does not change global variables.

In order to do what you claim, AGS would have to separately keep track of how each room script changes global variables and somehow undo this. This is not how it works though. AGS resets just the room state, for instance the coordinates of objects.

Crimson Wizard

Quote from: Khris on Mon 23/10/2023 16:22:19ResetRoom() does not change global variables.

Indeed, ResetRoom was never supposed to change anything global.

There's one known case which may result in "loosing" global variable value: it's when you declared variables in the header without "import" keyword. This leads to variable "duplication" effect, where each script, including room script, receives a copy of a variable instead of using same shared one.

https://adventuregamestudio.github.io/ags-manual/TheScriptHeader.html

eri0o

If you have a room that always is going to be reset after leaving, you can instead just set the room number to something above 300 (and, erh, below 999), because rooms outside of the 0-300 range never save their state.

AndreasBlack

#4
I'm gonna try it again, perhaps i messed something up. Wouldn't surprise me one bit(!) Let's say it wouldn't be the first time i messed something up while 'coding'!  (laugh)

Thanks for all the replies!

Edit: It's working now, i wished i'd screen captured my stuff. Cause this is the second time where something really odd happens, but it was probably something else i was doing that was causing it.
 


heltenjon

So what you're doing is that you have the same AGS room posing as different identical hotel rooms in-game, and keeping the small differences (lamps turned on, objects visible etc.) stored in variables?

SMF spam blocked by CleanTalk