Inheritable Rooms

Recommended Tutorials for Version 4

Inheritable Rooms

Postby Eldude » Thu Nov 05, 2009 3:32 pm

Please note: You need the PRO version of DSGM to use inheritable rooms.

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.

inheretable.jpg
Making a room inheritable with the drop down menu.
inheretable.jpg (17.79 KiB) Viewed 361 times


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.
Attachments
inherit1.nds
Demo of above example.
Made with DSGM 3.1 Pro
(278.56 KiB) Downloaded 49 times
inherit1.xds
Made with DSGM 3.1 Pro
(1.23 KiB) Downloaded 48 times
If you do not like my post, PM me to let me know and I will edit it.
Available to program your game.(not help you program it)
PM me your proposals. I want to see graphics and story as a minimum.

My Scratch Page: http://scratch.mit.edu/users/Eldude
Image
User avatar
Eldude
 
Posts: 5799
Joined: Thu Jun 26, 2008 9:46 pm
Location: A good place!
Current Project: Coding for one of you!

Re: Inheritable Rooms

Postby Kiriashi » Sat Nov 21, 2009 1:22 am

Thanks for the tutorial Eldude!

Twas' quite helpful. :lol:
User avatar
Kiriashi
 
Posts: 62
Joined: Wed Feb 11, 2009 6:28 am
Location: Behind you with a knife... a big knife.
Current Project: Just learning for now..

Re: Inheritable Rooms

Postby Eldude » Sat Nov 21, 2009 9:24 am

Glad someone noticed my hard work!
If you do not like my post, PM me to let me know and I will edit it.
Available to program your game.(not help you program it)
PM me your proposals. I want to see graphics and story as a minimum.

My Scratch Page: http://scratch.mit.edu/users/Eldude
Image
User avatar
Eldude
 
Posts: 5799
Joined: Thu Jun 26, 2008 9:46 pm
Location: A good place!
Current Project: Coding for one of you!

Re: Inheritable Rooms

Postby Metatarsals » Sun Nov 22, 2009 12:53 am

Very helpful and efficient, thumbs up and thank you
Building an Engine
User avatar
Metatarsals
 
Posts: 741
Joined: Sun Jul 26, 2009 5:38 pm
Location: Where Leprachauns doth lie
Current Project: PacMan E [Beta]

Re: Inheritable Rooms

Postby Nickydude » Tue Mar 02, 2010 3:21 am

I was hoping there was some sort of function ability and this will do nicely, thanks Eldude.
Supporting DS Game Maker all the way!
Pro Version
Best Regards,
Andy.

My unofficial community Guide To DS Game Maker
User avatar
Nickydude
 
Posts: 81
Joined: Tue Feb 23, 2010 11:28 pm
Location: UK

Re: Inheritable Rooms

Postby Eldude » Tue Mar 02, 2010 3:33 am

As per most of my tutorials, this one is out dated. This one will still work but there is an action called "Inheritable switch room" now which does the same as "switch room" but its easier to know what it does with the new name.
If you do not like my post, PM me to let me know and I will edit it.
Available to program your game.(not help you program it)
PM me your proposals. I want to see graphics and story as a minimum.

My Scratch Page: http://scratch.mit.edu/users/Eldude
Image
User avatar
Eldude
 
Posts: 5799
Joined: Thu Jun 26, 2008 9:46 pm
Location: A good place!
Current Project: Coding for one of you!

Re: Inheritable Rooms

Postby James » Tue Mar 02, 2010 8:17 am

It is slightly different. It does not include transition checking.
Image
Image
Copy at will
User avatar
James
Site Admin
 
Posts: 5277
Joined: Mon Feb 25, 2008 9:59 pm
Location: United Kingdom

Re: Inheritable Rooms

Postby James » Tue Mar 02, 2010 8:21 am

Nickydude: Retake the screenshots and post them.

Eldude: Redo the example.

Me: Redid the text.
Image
Image
Copy at will
User avatar
James
Site Admin
 
Posts: 5277
Joined: Mon Feb 25, 2008 9:59 pm
Location: United Kingdom

Re: Inheritable Rooms

Postby Nickydude » Tue Mar 02, 2010 2:00 pm

As per most of my tutorials, this one is out dated.


Yes, I realise now and put all examples in V4.5.

Me: Redid the text.


And I just redid it before reading this post. :roll: :P

Nickydude: Retake the screenshots and post them.


inheretable.jpg
inheretable.jpg (12.16 KiB) Viewed 372 times

Done.

just as an aside, any 'rooms' I have as functions are called 'func_function-name'. E.G: func_movement.
Supporting DS Game Maker all the way!
Pro Version
Best Regards,
Andy.

My unofficial community Guide To DS Game Maker
User avatar
Nickydude
 
Posts: 81
Joined: Tue Feb 23, 2010 11:28 pm
Location: UK

Re: Inheritable Rooms

Postby bearglove » Tue Mar 09, 2010 10:36 am

nice to know any of the little kinks were worked out of this system. still browsing around to remind myself of how to do things that I want to get done...on to finding out if save files are working now...
User avatar
bearglove
 
Posts: 387
Joined: Tue Jan 20, 2009 6:14 am
Location: Bellingham, Wa, United States
Current Project: Advent DS<codename>


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest