Persistent? Yes or No?

Q

Qasura

Guest
Hey,

I posted a question some weeks ago:

"I have a question, it's about my inventory system. I just want to make another room for the inventory and everytime when I press "E" then it should change to the inventory and pause the game. And when I press "E" again then it should go back to the game. But I dont know how to do. I mean when I go back to the game then the room restart(Player is on his start position). So, how can I change this?"

And this was the answer:

"What you need to do is make the room persistent. This can be done through code quite simply like this:

Code:
room_persistent = true;
And then when you return to the room you must switch it off again otherwise the room will always be persistent. This can be controlled with a global variable, for example. You would have a controller object with a CREATE event like this:

Code:
global.inventory = false; // Initialise the global variable to a value, false in this case
Then a ROOM START event like this:

Code:
if global.inventory == true
{
room_persistent = false;
global.inventory = false;
}
This will switch OFF persistence when the room is entered, but ONLY if the inventory global variable is true (peristent objects don't run their create event on re-entering the room, but they DO trigger their room start events). Then in the same controller you'd have a key that goes to the inventory room:

Code:
if keyboard_check_pressed(ord("i"))
{
room_persistent = true;
global.inventory = true;
room_goto(rm_Inventory);
}
Tis sets persistence to true for the current room and flags the glbal variable we use to check as true as well, then goes to the inventory room.

In this way what you want should work"

But I have one more question. Can I set the persistence in that Code to true?

Code:
if global.inventory == true
{
room_persistent = false;
global.inventory = false;
}

Thanks!
 
In my opinion: NEVER use room persistence. Object persistence is fine, but room persistence is a huge ordeal. What are you gonna do about your inventory when you get to saving your game? You can't "save" a persistent room to a file, so you'll have to convert all that stuff to "data" anyway. Might as well just make it saveable data now.

Check out my tutorials on save data.
https://forum.yoyogames.com/index.php?threads/simple-advanced-ds-map-based-save-system.11613/
 

CMAllen

Member
In my opinion: NEVER use room persistence. Object persistence is fine, but room persistence is a huge ordeal. What are you gonna do about your inventory when you get to saving your game? You can't "save" a persistent room to a file, so you'll have to convert all that stuff to "data" anyway. Might as well just make it saveable data now.

Check out my tutorials on save data.
https://forum.yoyogames.com/index.php?threads/simple-advanced-ds-map-based-save-system.11613/
Room persistence has uses, but mostly it's a convenience thing for when your game is going to switch to a different 'room' but the player isn't technically 'leaving' the previous room. Such as a full-screen menu or the like. In either case, however, it's not something that is typically enabled and LEFT that way. A room is set to persistent before the game changes rooms, and then switched off when the game comes back. The room just gets held in limbo while the user is interacting with some other part of the game. But, you're definitely right. A persistent room is not a good way to 'store' anything. Use sparingly if at all.
 
Q

Qasura

Guest
But do you have another solution for the variables in the game?
 
Q

Qasura

Guest
I also dont want to save the game. Just the variables for the inventory.
 

obscene

Member
I don't know how you are doing your menu now, but when I think of making an entirely new room just for an inventory I am deeply confused. It's totally not necessary. Just draw the menu in the room you are in! I assume you have an object that draws a menu so why do you need to switch rooms in the first place?
 
Q

Qasura

Guest
I'm making a game for a challenge(just like ludum dare). And a menu is not necessary. So I just want an easy way
to have an inventory, so I created a room with buttons you can interact with. Please just ask my question, how
do I save the different variables if persistence isn't the solution.
 
T

TheseDangBots

Guest
But I have one more question. Can I set the persistence in that Code to true?
The way I'm reading the bit of code you're asking about, no. When you go to the non-inventory room, it checks if you've just returned from looking at your inventory. If you have (global.inventory = true), it sets the current room's persistence to false since you're in the room. Setting it to true would make it persistent while you're there and not just when you're in the inventory room.
 
Q

Qasura

Guest
When I try the code it works, but if you say that is not a good solution,
what can I do?
 

CMAllen

Member
I don't know how you are doing your menu now, but when I think of making an entirely new room just for an inventory I am deeply confused. It's totally not necessary. Just draw the menu in the room you are in! I assume you have an object that draws a menu so why do you need to switch rooms in the first place?
It's a bit like a FSM. What's in the room is the only code that can execute while in that room. However, all the stuff in the room you just left is still relevant. You just don't want any of its code executing until you get back. Otherwise, now you have to tell all those objects in the active game room how to behave when this other menu/ui/whatever is active and in use, as well as code them to look for that condition in the first place.
 

CMAllen

Member
Instance deactivate all... mute all sound, draw black rectangle over screen and draw menu!
Yup. I didn't mean to say that this was a 'good' way of handling it. Only that it's a way to handle it. But I get why someone would take the room route for different game functions. It's easy to understand. This room does X. That's all it does. This room does Y. That's all it does. And so forth. The reality of actually controlling all that is another matter.
 
Q

Qasura

Guest
But that's more complicated for an inventory(It has also a crafting system). I tried it,
but it's not effective especially to find a good position for the inventory slots.
 
Top