Sample room code

Started by dbuske, Sat 11/12/2010 21:50:33

Previous topic - Next topic

dbuske

Would it be possible for someone to send me a sample room script for a game.  A room script would give me info on how to properly do a script.  I am sure I am doing things in a stilted way in my game "Danse Macabe."
Thanks to anyone who responds.
What if your blessings come through raindrops
What if your healing comes through tears...

Tamanegi

I'm not sure what you want, to be honest.

There is no such thing as a definite "room script" except for a collection of everything that will happen in the room. You set the background, you paint the walkable areas, objects and hotspots, and you select which actions will trigger something when clicked on in a specific mode, walked on, the player entered the room and so on. The only scripting to be done is the scripts that will run triggered by clicks, and those scripts are auto-generated (to be filled with commands by yourself) and auto-named when you click on the specific situation in the "edit room" window.
What to include and what not greatly depends what exactly should happen in the room. You could make a functionable room without writing a single line of script code.

What exactly is the problem you have? If you can be more specific, we might be able to help you better.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Khris

dbuske, why don't you post one of your room scripts and we can point out what could be done differently or more easily?

monkey0506

This is a sample of a room script I use in rooms in which I want absolutely no interactions to take place:

Code: ags
// room5.asc script file


..on a slightly more serious note..there's not really any way to provide a "generic" room script (as has been said) simply because what you put in the room script controls things entirely specific to that room.

dbuske

I just wanted to see how an experienced game maker goes about it.
Just general help.
What if your blessings come through raindrops
What if your healing comes through tears...

monkey0506

An experienced game maker understands that there's no such thing as a generic room script, since generally room scripts only contain the automatically generated room event handlers that handle code specific only to that room.

Give us examples of what you want to accomplish in your sample room, and we can help provide you with code examples of how that can be done; we cannot, however, just pull some magic code out our rears that will make every room instantaneously work exactly how you want it to with no modifications..unless you want every single room to call AbortGame..coz that's easy!

Tamanegi

Ok, really:

How an experienced game maker (that I'm not) would go about "it" is dependend on what "it" is.

What should happen in the room?

It's like asking how an experienced painter would paint a picture. It depends on what the picture should show. Buildings? You need a vanishing point and warm/cool grays. People? Probably soft brushes, skin tones, and preferably models. Landscape? You can do it Bob Ross and just stip the canvas with large brushes. And so on.

Okay, let's just say you have a sign somewhere in the room. You want the player to go there and read it aloud when he clicks it with "look at".

First, you go to "Edit room" on the right-hand side. The window now shows the empty room, probably a black or pink rectangle. Click on "change" next to "Background", and you will be able to select a background image. This could have the sign already in it.
Next, click on the selector "show room's" and select "hotspots". Look right and make shure "Hotspot 1" is selected. Above the main window are various tools for painting. Select the line tool and roughly outline the sign with it. Then select the fill tool and fill the area, which should turn blue. If the while screen turns blue, click the undo button near the other tools and close any gaps in your outline before filling it again.
After that, look right again. There are the properties of that hotspot. A hotspot is a specified area in the background that the player can interact with if you choose to make interactions. Go to "Name" and name it "hSign" for example. The "h" should remind you it's a hotspot. This is the script name of that hotspot. Theoretically, you could name it anything you want.
Now you still need to define a walkable area, or the character can't move. A walkable area is just that: An area that the player can walk on. So select "show this room's: walkable areas" from above the room image, select "walkable area 1" on the right side, and paint the walkable area the same way you painted the hotspot earlier.

So far, you only set up the room. No scripting done yet.

Click on the small lightning bolt above the properties. You will see a list of possible triggers, as "interact hotspot" etc. Point your mouse cursor at the spot you want the player to walk to before he reads the sign, and look above the main window, where you are given coordinates. Remember them or write them down. Now click on "looks at hotspot" and then click on the "..." that appear next to it. You will be taken to the script area.
There you should see something like
Code: ags

function hSign_Look()
{

}

Between the "{ }", you will write your code.
Put the following there:
Code: ags

  player.Walk(x,y,eBlock,eWalkableAreas);
  player.Say("This sign reads: Blah blah blah");

For x and y, put the coordinates you wrote down. The "This sign reads" and so on can be replaced with whatever you want the character to say.

That's it.

This room script does nothing except wait for the player click on the sign while in "look at" mouse cursor mode, then move the player character to that sign and make him say something. It won't do anything else. Some steps aren't really necessary (like the renaming of the hotspot or making a walkable area - you could just use "eWalkAnywhere" instead of "eWalkableAreas"), but that's how an experienced maker would do it, it's clean programming.

If that doesn't answer your question, I'm sorry. But without knowing what you want to do, there is ABSOLUTELY NO WAY to tell you how it is done. Honestly. A room script is, and I repeat myself, just a collection of all the things you want to happen in the room when certain things are done by the player. Aside from that, you don't need anything in the script. It might sound redundant, but you only need in the room script what you need. If you say "I need this", then put it there. If you say "I don't need this", leave it out.
Knowing exactly what you need for what you want to archieve is the tricky part, and the one besides graphics that eats the most time when making a game.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Wyz

I guess the TS wants to see some sample code to test out various coding styles. But most people are a bit reluctant in posting room code because things can get messy really quickly. Actually forming a room script is a process rather than just the script, you add to it and once it works and it's tested the code because invisible in the eyes of the coder (but is should become visible real quickly in case of bugs :D).

http://www.youtube.com/watch?v=Yu6djXYlemg

The best I can do is give you the link to a screen capture of the making of a hour game I did a while back. Play it slowly and in HD, then you could see the code forming.
I could give you room script of some of my games, but there is really no point.
Life is like an adventure without the pixel hunts.

dbuske

#8
I do know the general way to script and can do alot.  I just wanted to see generally how someone more experienced goes about it.  I wasn't going to copy the scripts or anything like that.
I wasn't having a problem and wasn't asking for any specific help.
But thanks for the replies especially Tamenegi.
What if your blessings come through raindrops
What if your healing comes through tears...

Tamanegi

So you just want a sample room script that you can analyse and see what it does and how?
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Khris

I was going to link you to OpenQuest; it uses obsolete code though.
There also DemoQuest, not sure about its current state/usefulness though.

I guess an open source demo game with a few rooms that explains some basic mechanisms would be a very helpful asset.

dbuske

Well my game is coming along good.  I have scripting for every room.  I can walk through the whole game.
What I have left to do is, sound effects, and I left the tough puzzles for the end.  And, I need to tweak a number of small things such as the NPC facing the Main character during dialogs.
The puzzles will be the toughest, for I have to search for how to actually do the puzzles.
Thanks for your help Guys, I apreciate it.
What if your blessings come through raindrops
What if your healing comes through tears...

SMF spam blocked by CleanTalk