Overview
Inheritable rooms are just rooms that can be called from any other room. You do not switch to this room (you do use the switch room action to use them thou) but instead you pull in all the actions from the inheritable room into your existing room.
In programming language what we are doing is creating a function and then calling that function.
What are they good for?
The main reason for using inheritable rooms is to save on repeating blocks of actions.
In my example I am going to be moving a sprite in two rooms. Instead of adding the movement actions to every room, I just add it to one room and switch to the movement actions room (or call the function) from the rooms where I want to move the sprite.
Method
I will work a little backward and start with Room_3 which will be my inheritable room. Do not make the first room Inheritable!
The game will move the cactus sprite. When you hit the balloon sprite it will change rooms. All the movement actions will be in a totally separate room (Room 3)
I start DSGM, start a new project. Then I add 2 more rooms to make 3 including the default starting room.
I will make room 3 Inheritable by selecting the drop down tab and changing the default of Non Inheritable to Inheritable.
Add these actions to Room 3 ( I know I could have just used "Move Sprite with D-Pad action but I wanted to show a simple example)
ROOM 3
- Code: Select all
Declare Global x;Whole Number;112
Declare Global y;Whole Number;80
Jump to X 1;0;x
Jump to Y 1;0;y
If Button Press Held;Right
Set Variable x;x + 1
End If
If Button Press Held;Left
Set Variable x;x - 1
End If
If Button Press Held;Down
Set Variable y;y + 1
End If
If Button Press Held;Up
Set Variable y;y - 1
End If
Note that I have declared X and Y as Global variables and set there values as to where I want the sprite to start in room 1.
After that the sprite will remain in the same position, even after changing rooms.
Room 1 and 2 setup.
I place the sprite I want to move as sprite 0 as this is the sprite I specified in the inheritable room that will move.
Then I place the balloon on the screen as sprite 1.
Simple actions to detect the collision and switching rooms are added. Room 1 will switch to 2 and vica versa.
ROOM 1
- Code: Select all
Switch Room Room_3
If Collision 1;0;1
Inheritable Switch Room Room_2
End If
Output Text 0;0;0;Room 1
Note that the first action is to switch room to room 3. As room 3 is inheritable, we will not actually switch to this room but instead, include the sprite movement actions into this room so that they can be used to move the sprite.
The actions are not duplicated in room 1 and 2 but used from room 3 where they are, but included in any room that you call the room from. Hope that makes sense.
The rest of the actions are to detect the collision and then switch to the next room. I included an output text action so you can keep track of which room you are in but it is not required.
ROOM 2
- Code: Select all
Switch Room Room_3
If Collision 1;0;1
Inheritable Switch Room Room_1
End If
Output Text 0;0;0;Room 2
Room 2 is the same as room 1 but instead it switched to room 1 instead of room 2.
Conclusion
When using Inheritable rooms you need to use the "Switch Room" action to include the Inheritable rooms actions in any non inheritable room(you will not actually switch to this room). You could use inheritable rooms inside inheritable rooms but that may get complicated.
You could use 1 set of movement actions/sprite animation actions or what ever and just call the room from any other room in your game to save having to add them all to every room. You could set up an inheritable room to populate the scoring screen of every level of your game so you would not have to add this to every room. You are limited by your imagination.
Any problems... don't ask me!
The goodies
I have included the .xds and .nds for your pleasure.



