room_instance_add?

So… I'm 100% sure my code runs, everything in it runs. But there is one little line in a chain of events
that never works. You see, during an if statement, i have 4 things happen. 3 out of those 4 work.
The 4th one is a room_instance_add, used to create an instance in another room. When
I move my player to that room, having full well witnessed the 3 other things working,...
I arrive in that other room and there is no instance. The debugger doesn't show it, nothing happens,
it's just not there.
I was under the impression that room_instance_add is supposed to add an instance to another room,
which upon arriving in that room, is actually created?

Maybe I don't understand how to utilize this function?
 

jo-thijs

Member
So… I'm 100% sure my code runs, everything in it runs. But there is one little line in a chain of events
that never works. You see, during an if statement, i have 4 things happen. 3 out of those 4 work.
The 4th one is a room_instance_add, used to create an instance in another room. When
I move my player to that room, having full well witnessed the 3 other things working,...
I arrive in that other room and there is no instance. The debugger doesn't show it, nothing happens,
it's just not there.
I was under the impression that room_instance_add is supposed to add an instance to another room,
which upon arriving in that room, is actually created?

Maybe I don't understand how to utilize this function?
Is your room by any chance set to be persistent?
 

mimusic

Member
I didn't know about this function until now, but looking at the example in the docs makes me think that you can't actually modify a room directly.

Code:
global.rm = room_add();
room_assign(rm_Base, global.rm);
room_instance_add(global.rm, 100, 100, obj_Player);
So instead of directly addressing rm_Base, it seems that a variable is made that holds a new room created during run-time, with all the contents of rm_Base added to it. At this point, for all intents and purposes, the new room is the same as rm_Base... BUT with the added benefit of being mutable / changeable. I guess it's the same way that objects work, where you can't actually change the source object at run-time, but you can make any changes you want to individual instances of that object.

this is entirely guess work though, so the problem you're having could be for an entirely different reason.
 
I didn't know about this function until now, but looking at the example in the docs makes me think that you can't actually modify a room directly.

Code:
global.rm = room_add();
room_assign(rm_Base, global.rm);
room_instance_add(global.rm, 100, 100, obj_Player);
So instead of directly addressing rm_Base, it seems that a variable is made that holds a new room created during run-time, with all the contents of rm_Base added to it. At this point, for all intents and purposes, the new room is the same as rm_Base... BUT with the added benefit of being mutable / changeable. I guess it's the same way that objects work, where you can't actually change the source object at run-time, but you can make any changes you want to individual instances of that object.

this is entirely guess work though, so the problem you're having could be for an entirely different reason.
I didn't know about this function until now, but looking at the example in the docs makes me think that you can't actually modify a room directly.

Code:
global.rm = room_add();
room_assign(rm_Base, global.rm);
room_instance_add(global.rm, 100, 100, obj_Player);
So instead of directly addressing rm_Base, it seems that a variable is made that holds a new room created during run-time, with all the contents of rm_Base added to it. At this point, for all intents and purposes, the new room is the same as rm_Base... BUT with the added benefit of being mutable / changeable. I guess it's the same way that objects work, where you can't actually change the source object at run-time, but you can make any changes you want to individual instances of that object.

this is entirely guess work though, so the problem you're having could be for an entirely different reason.

Auch if that's the case that's a bitter pill to swallow. I'd basically be flooding my game with "duplicated rooms" each time i need this code to run. Kind of frustrating that such an important concept can't be done in the engine. Like... access things in other levels/rooms/dungeons,... Seems so important but you really have to work your way around the limitations here :(
 

jo-thijs

Member
all my rooms are set to persistent, as what is in those rooms need to be remembered when i leave and get back to them :)
Well then there is your problem.
room_instance_add only works for non-persistent rooms.

I didn't know about this function until now, but looking at the example in the docs makes me think that you can't actually modify a room directly.

Code:
global.rm = room_add();
room_assign(rm_Base, global.rm);
room_instance_add(global.rm, 100, 100, obj_Player);
So instead of directly addressing rm_Base, it seems that a variable is made that holds a new room created during run-time, with all the contents of rm_Base added to it. At this point, for all intents and purposes, the new room is the same as rm_Base... BUT with the added benefit of being mutable / changeable. I guess it's the same way that objects work, where you can't actually change the source object at run-time, but you can make any changes you want to individual instances of that object.

this is entirely guess work though, so the problem you're having could be for an entirely different reason.
Auch if that's the case that's a bitter pill to swallow. I'd basically be flooding my game with "duplicated rooms" each time i need this code to run. Kind of frustrating that such an important concept can't be done in the engine. Like... access things in other levels/rooms/dungeons,... Seems so important but you really have to work your way around the limitations here :(
Not exactly.

room_instance_add changes data from the room.
However, when moving to a persistent room you have moved to before already, you won't load the room, but the instances that were saved when leaving the room instead.
Therefor, moving to a persistent room doesn't load the room, which is what you changed.

A possible solution for your issue can be found here:
https://forum.yoyogames.com/index.php?threads/room_go_to-in-series.64121/

To be fair though, I think persistent rooms should never be used.
They tend to cause a lot of trouble and you can relatively easily implement all the handy features yourself.
Sometimes you'll even be able to implement it much more efficiently as a lot of the data in the room is irrelevant to save.
 
Well then there is your problem.
room_instance_add only works for non-persistent rooms.



Not exactly.

room_instance_add changes data from the room.
However, when moving to a persistent room you have moved to before already, you won't load the room, but the instances that were saved when leaving the room instead.
Therefor, moving to a persistent room doesn't load the room, which is what you changed.

A possible solution for your issue can be found here:
https://forum.yoyogames.com/index.php?threads/room_go_to-in-series.64121/

To be fair though, I think persistent rooms should never be used.
They tend to cause a lot of trouble and you can relatively easily implement all the handy features yourself.
Sometimes you'll even be able to implement it much more efficiently as a lot of the data in the room is irrelevant to save.
Ah yes, my previous post. That one is a bit related to my question in this post.
Maybe I'll specify what it is exactly that I'm trying to do.
I have a player object (obviously) and my game has a nice day and night cycle. The player has to "chop wood" from trees, alongside other things, in order to survive. I can make my trees grow, chop 'em down, collect wood... and so on. All of that works. My problem is that they have to grow back , one "stage" of growth per day. When the player goes back to a sleeping area, he will skip to the next day (which i got working). But now...
All trees across different rooms also need to go "stage +1"!

At first I thought: no problem! When my player goes "to sleep", the screen fades to black and my timer is reset to 0, and the day is incremented with +1. During this black screen, it's the perfect moment to teleport my player briefly to all maps with trees, as my trees grow 1 extra stage at the exact beginning of a day.


Basically my time system increments. If variables called "TimeHours" and "TimeMinutes" both equal 0, it's the exact frame of the start of the next day, which can happen only 1 frame per day. This is the moment something in a room triggers to grow.


If i can't get this to work properly, My project is in trouble :p As trees aren't the only thing that I need to change at the beginning of a new day.


Up untill now, everything I have already works like a charm, it's that "day is over: go to sleep => next day starts and all instances grow back across multiple rooms" concept that i can't get to work.
 

jo-thijs

Member
Ah yes, my previous post. That one is a bit related to my question in this post.
Maybe I'll specify what it is exactly that I'm trying to do.
I have a player object (obviously) and my game has a nice day and night cycle. The player has to "chop wood" from trees, alongside other things, in order to survive. I can make my trees grow, chop 'em down, collect wood... and so on. All of that works. My problem is that they have to grow back , one "stage" of growth per day. When the player goes back to a sleeping area, he will skip to the next day (which i got working). But now...
All trees across different rooms also need to go "stage +1"!

At first I thought: no problem! When my player goes "to sleep", the screen fades to black and my timer is reset to 0, and the day is incremented with +1. During this black screen, it's the perfect moment to teleport my player briefly to all maps with trees, as my trees grow 1 extra stage at the exact beginning of a day.


Basically my time system increments. If variables called "TimeHours" and "TimeMinutes" both equal 0, it's the exact frame of the start of the next day, which can happen only 1 frame per day. This is the moment something in a room triggers to grow.


If i can't get this to work properly, My project is in trouble :p As trees aren't the only thing that I need to change at the beginning of a new day.


Up untill now, everything I have already works like a charm, it's that "day is over: go to sleep => next day starts and all instances grow back across multiple rooms" concept that i can't get to work.
This sounds easier than what I originally thought you were trying to do.

If I understand you correctly, can't you just keep a variable "birth" in the tree objects, keeping track of the day in which they were created,
have a global variable "global.day_count" that keeps track of the current day,
and make tree objects compare their "birth" with "global.day_count" in their room start event, making them grow accordingly?
 
This sounds easier than what I originally thought you were trying to do.

If I understand you correctly, can't you just keep a variable "birth" in the tree objects, keeping track of the day in which they were created,
have a global variable "global.day_count" that keeps track of the current day,
and make tree objects compare their "birth" with "global.day_count" in their room start event, making them grow accordingly?
I thought about that, problem is … I have years xD My days are reset to 0 when a new year arrives.
So imagine not visiting a map during a whole year: that map would be a forest by then. But the days number determines that and that is set back to 0 at a new year...


Basically the shortest path I thought I could take was: New day? => change room 1, change room 2,... Wake up. Play game, gather resources, defeat enemies, upgrade weapons,... Go to sleep. New day? => repeat.


(a new day can ONLY be true if timehours & timeminutes = 0, so that's the moment growth needs to happen at multiple rooms, leaving out the need to track which day, which year,... But I guess I tried taking a shortcut that ended up as a dead end :/ )
 
this is my general idea up until now:


if (SkipDay = true) && (InputLeftClick_Rel)
&& (OBJ_Mouse.x >= (OBJ_Camera.Display_Width/2) - 40 -21
&& OBJ_Mouse.x <= (OBJ_Camera.Display_Width/2) - 40 +20
&& OBJ_Mouse.y >= (OBJ_Camera.Display_Height/2) + 24 - 5
&& OBJ_Mouse.y <= (OBJ_Camera.Display_Height/2) + 24 + 4)
//Skipday = true if player moves into the bed, the rest is just a button to press (go to sleep? button "yes" clicked)
{
OBJ_Player.x = Bed_X + 22;
ActivateSkipDayMenu = false; //turn off the on screen question of "go to sleep?"
FadeOut = false; //end fade-out, turns back on when player moves into bed and causes a screen to gradually grow black
FadeIn = true; //start fade-in, start showing everything again
}

if (FadeIn = true)
{
FadeOut_Alpha -= 0.02; //a black overlay sprite that now goes back from alpha = 1 to alpha = 0
if (FadeOut_Alpha <= 0) //when the screen is fully visible again (handled in draw gui event)
{
MoveOutOfBed = false; //don't pay attention to this, this is needed if you want to move out of the bed and NOT skip the day (the "no" answer to the question "go to sleep?")
if (SkipDay = true)
{
TimeMinutes = 0; TimeHours = 0; TimeDays += 1; DaysDisplay += 1; //set day to the next one and reset day timer

//RIGHT HERE THIS IS WHERE I THOUGHT A TRIGGER COULD HAPPEN TO GROW STUFF ON OTHER ROOMS

SkipDay = false; //turn this off, so it can be turned on again when moving back into bed
}
FadeOut_Alpha = 0;
FadeIn = false;
GamePause = false; //this allows player to move again, or pull up pause menu's again
}
}
 

jo-thijs

Member
I thought about that, problem is … I have years xD My days are reset to 0 when a new year arrives.
So imagine not visiting a map during a whole year: that map would be a forest by then. But the days number determines that and that is set back to 0 at a new year...


Basically the shortest path I thought I could take was: New day? => change room 1, change room 2,... Wake up. Play game, gather resources, defeat enemies, upgrade weapons,... Go to sleep. New day? => repeat.


(a new day can ONLY be true if timehours & timeminutes = 0, so that's the moment growth needs to happen at multiple rooms, leaving out the need to track which day, which year,... But I guess I tried taking a shortcut that ended up as a dead end :/ )
Then also keep track of the year?
 
I'm sure I'm missing either something very obvious that can be fixed, or something very difficult that requires rethinking the whole structure of those rooms and objects
 
Top