Need to create a gate/barrier...

Started by AuraBoyX, Fri 20/02/2004 11:11:50

Previous topic - Next topic

AuraBoyX

Hello. I love this new program as I have wanted to find something like this for years (used to be a huge fan of the Sierra games). I am an artist and I am having a ball creating the animations and the backgrounds/objects and I have been experimenting making a few playable screens to get used to the interface...

The problem is, one of my scenerios has a gate in the middle of the screen that is locked. I want the character to be blocked by the gate until he unlocks it. The unlocking is not the problem its the actual gate. My character keeps walking through it. It seems to me that I would have to create two walkable areas and restrict one until the gate is unlocked. (Or even as simple as the gate being closed from either side without unlocking).

Under investigation I found the RemoveWalkableArea and Restore WalkableArea commands. But I havn't attempted scripting yet so I really don't know how or where in the interface to enter these commands.

If anyone could please show me what to type and where/how in the interface (or if there is an easier way) I would be very appreciative.

Also if anyone has the *Basics* on scripting that would be cool too. I see all these cool scripts on here and I want to be able to enter them in the right places. A good example is RemoveWalkableArea (int areanum)... All the online help files and the manual all seem to assume one knows the basics of scripting. I don't know if the parentheses are suppose to be there or not (I am assuming not) and I THINK areanum means which area number. No idea what int means lol!  :o

I am a wizard at the design/animation but kinda suck with the code!  ;D

Any help is appreciated.
AuraBoyX
www.notinpublic.com

ThunderStorm

I really recommend to learn scripting. It's not too hard, and it opens up whole new worlds in game design. Have a look at this scripting tutorial - I think it's also part of the help file that comes with AGS.

Good luck!

Olzn

how about creating a hotspot  at the gate which stops the charater from walking through? and when the character is using the inventory item that's opening the gate you'll disable that hotspot?

RickJ

You need to creat multiple walkable areas.  Disable the walkable area under the gate when it is closed.  Enable it when the gate is open.

Alynn

Another thing you can do is not put a walkable area behind the gate at all, and only if you click the gate and it is unlocked (like interact with object) the gate will open, the character walks through it, The gate closes and you do the scene transition.

RickJ

You need to creat multiple walkable areas.  Disable the walkable area under the gate when it is closed.  Enable it when the gate is open.

[edit]
I just composed a lengthly explanation to add to the above and I just lost it to the big bit bucket in the sky.   I need to go to work just now but I will post a detailed explanation tonight.  Sorry
[/edit]

AuraBoyX

#6
QuoteI just composed a lengthly explanation to add to the above and I just lost it to the big bit bucket in the sky.   I need to go to work just now but I will post a detailed explanation tonight.  Sorry

Thanks! I would really appreciate it and any other help you have offered already! :) I am so excited about this game engine. Once I have the basics down I will be able to experiement and learn (in this instance being introduced to scripts). I have been doing some backgrounds / objects / animation with my tablet PC in Flash (which I am exporting to use with the engine) and the results are awesome! The fact that I KNOW this engine can produce good results has me more motivated than I ever have been before.

Are there any complex sample games (more than the demo) that can be picked apart with instructions on how to do certain things. It would be helpful to actually PLAY something and be able to cross reference instances with something specific and direct to say; "Ah, that's how I do that."

Thanks again!

Christopher / AuraBoyX

check out my art website www.notinpublic.com  ;D


AuraBoyX

Quote from: ThunderStorm on Fri 20/02/2004 15:42:47
I really recommend to learn scripting. It's not too hard, and it opens up whole new worlds in game design. Have a look at this scripting tutorial - I think it's also part of the help file that comes with AGS.

Good luck!

This tuturial is great I am doing it now. Thanks. When getting started it's hard to pinpoint exactly which resource to use when there is a wealth of things whirling around one's head. I remember looking through the tutorials section but I guess I was a little overwhelmed and overlooked this when looking for a more specific problem. (i.e. restricting walkable areas versus scripting in general). That's the great things about these beginner boards and I want to thank everyone with experience who takes the time to read and answer. You are all really doing a good service to people in need!

Let the Karma reign via great adventure games!!!

Thanks :)

Christopher / AuraBoyX
http://www.notinpublic.com

deedee

Hi! I'm also trying to figure out how to make a gate... i like the disable/enable walking areas idea... but i can't find how to do that. I don't know how to make walkable areas on or off.


thanks
There can be only one.

Scummbuddy

Im away from my computer, so I'm not exactly sure. check in the ags helpfile/manual for 'DisableWalkableArea' and 'EnableWalkableArea'

if anyone wants to back me up or correct me, please do
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

deedee

Nope. EnableWalkableArea doesn't seem to exist and i can't find an equivalent in the help file. I found enableregion (or something similar) but it's useful in this case; isn' it?
There can be only one.

SSH

This is one of the main niggles with the scripting langauge: inconsistent naming of functions!

ObjectOn/ObjectOff
EnableHotspot/DisableHotspot
RemoveWalkableArea/RestoreWalkableArea
character[XXX].room=player.room/character[XXX].room=-1;
EnableRegion/DisableRegion
GUIOn/GUIOff

and then you need to work out if speeds have bigger or smaller numbers as faster...  :-\
12

RickJ

#12
Aurora,

Sorry for taking so long.  I lost this thing twice so I hope you will find it useful.  Gotta go get some sleep now.

Rick


AGS Quick Tutorial: Opening/Closing a Gate
by Rick Jafrate



INTRODUCTION
This tutorial assumes the reader has some familiarity with the operation of the AGS editor. There are other well illustrated tutroials showing how to use the various features of the editor so it makes little sense to cover the same material here in a less adequate text format.  Check the sticky posts in the beginner's forum.


SCRIPTING OVERVIEW

Scripts
A script file contains a collection of statements or instructions that are executed by the AGS Game Engine. Such statements are normally terminated by a semi-colon character, ";". In AGS there is a global script file and one room script file for each room. The global script is always active and only one room script file is active at any given time (i.e. the room script associated with the current room). The AGS scripts are very similar to the "C" programing language,  

Comments
Comments are good things :). Although they don't have any affect on the compiler or game engine they do keep us poor stupid humans out of a lot of trouble. A comment is denoted by the occurance of double slash characters "//". The "//" characters and the remaining portion of the line are ignored by the compiler and are meant purely for human consumption.  

Variables
A variable is a portion of memory that has been given a name and a data type. The name is associated with a physical memory location by th AGS compiler and/or game engine. The data type determines how much memory must be allocated to accomodate the kind of data to be stored here. The most commonly used data types are string, and int.  A string variable is used to store text and an int variable is used to store numeric/integer values. Variables are defined in a script file by first entring th data type followed by the name as follows:  
   int MyVar;


Functions
A function is a container for script statements (or instructions).  Such statements consist of basic constructs such as if/else, assignemnts, integer arithmetic, and calls to other functions. Note: Math is evaluated from right to left in AGS and sometimes produces unexpected results. Functions must be defined before they are used. There are a number of functions that are pre-defined by AGS and are explained in the help document.  Functions return data, by default they return int data.  Because of this they can be used like variables. An example function is defined below that doubles a value and returns the result.
   // This function doubles the value and returns th result
   // The first line defines the name of the function and
   // the parameters that is uses.  In this case DoubleIt 
   // is the function name. It requires one parameter which 
   // is an integer named value.  The curly braces {} are
   // used to enclose the functions contnts.
   function DoubleIt(int value) {

      // Create a variable in which to store th result 
      int temp;

      // Calculate result
      temp = value + value;

      // Return the result
      return temp;
   }
 


Events
The AGS Game Engine executes scripts in response to the player's interactions with the game.  Programmers refer to such interactions as events.  Programs that are executed when an event occurs are referred to as event handlers.
   // Within the bounds of a subsequent event handler function 
   // in the same script file the DoubleIt() function could be 
   // used as follows:

   function room_a() {
      // AGS interaction triggers this function to execute
      Myvar = DoubleIt(10);  // Set MyVar equal to 20
   }


Interaction Editor
Event handler functions are created using the AGS interaction editor.  Select the desired interaction and then click on "Run Script" from the drop menu to create an event handler function.  The function name will be automatically assigned so don't modify the name or definition of such functions.

continued ...

RickJ

#13
STEP BY STEP

Animating The Gate
The first thing to is to darw a sequence of pictures of the gate in various stages of opening. The same sequence can be used for closing so only one sequence will be necessary. The sequnce can be stored as a series of frames in a single file or in multiple files (i.e. one frame per file).  Once the pictures are drawn they must be imported using the AGS Sprite Manager. Next use the View Editor to create a "view" or collection of animation loops.  In this case we will need only one animation loop.  So in Loop-0 assign the appropiate sprites to Loop-0's frames to depict the gate opening where frame-0 shows the gate closed and frame-n shows the gate open.  A summary of what we have done follows:

1.  Draw a sequence of pictures showing the gate opening.

2.  Import the picturs into the AGS Sprite Manager  

3.  Create a View and a Loop using the View Editor

Adding the Gate to the Room
At this point it is assumed that you have created a room and have imported a background picture. The background picture should be minus the gate; the gate will be added using an object. To add the gate first open the room file using the Room Editor. Next select the RoomEditor->Objects screen, click the New Object button, and then click on the background picture in the general location of the gate. The infamous blue cup should appear on the background image.  Now click on the Change Image button. A Sprite Manager type screen will appear.  Navigate to the closed gate sprite and double click on it. Now there should be an image of the closed gate on the background image.  Drag the gate image to it's proper location on the background.  The next last thing to do is to set a baseline. The base line determines if characters are drawn in front of or behind the gate.  If the character's baseline is above an object's it will be drawn behind the object and in front og the object otherwise. To set the gate's baseline click on the Set Baseline button and then position the cursor at the bottom edge of the gate and click. A horizontal line should appear denoting the location of the baseline.  A summary of what we have done follows:

1. Create a room and import the background image.

2. Create a new object in the room.

3. Change the object's image to the closed gate sprite.

4. Drag the gate image to it's proper location on the background.

5. Set the gate's baseline.

Adding a Gate Interaction
Using the same RoomEditor->Objects screen, click the Interaction button. The Interaction editor window should popup. Double click on Interact Object in this window to add an action to this event. A Configure Action dialog box appears.  Select "Run Script" from the drop down list and click the OK button to close the dialog box.  Now close the Interaction Editor window also. To see the event handler function we have just created select the RoomEditor->Settings screen and press the Edit Script button denoted by the {} curly bracs.  A Text Editor window will open showing the following script code:  
   // text script for room

   function object0_a() {
        // script for object0: Interact object
  
   }

The name of the event handler function we just created is object0_a and it has no parameters. Click on "File->Exit and save changes" from the Text Editor menu. A summary of what we have done follows:

1. Use Interaction Editor to create an event handler function

2. Use Text Editor to view newly created event handler function in the room script file.

Creating Walkable Areas
Before getting into more scripting there is one more thing we need to do to the room and that is to define walkable areas. We need to have at least three areas. One in front of the gate, one behind the gate, and one at the threshold of the gate.  The walkable area at the threshold of the gate should begin a little before the gate and end a little past the gate.  It should be large enough so that the character can't pass through when it's disabled.  To do this select the RoomEditor->Areas screen and then select "Walkable areas" from the drop down list.  Use the Spin control to select which walkable area to edit. Start with Area-1. Use the line and fill tools to draw the threshold area, Using the spin control select Area-2 and draw the walkable area in front of the gate. Select Area-3 and draw the walkable area behind the gate. A summary of what we have done follows:

1. Add walkable area #1 at gate threshold

2. Add walkable area #2 in front of gate

3. Add walkable area #3 behind gate

Making it All Work
Now it's programming time!!! Let's start by opening the Room Script file with the Text Editor. Select the RoomEditor->Settings screen and clicking on the {} button as we did earlier.  Use the cursor keys to navigate around the the file and juststype to insert text at the cursor.  

The first thing to do is to define constant values to represent the states of the gate. All this does is put a name to a numeric value for our convenience.  This is done using the #define directive as follows.
   // define some constant values
   #define OPENED -1000
   #define CLOSED -1001

I prefer using large negative numbers when defining such terms.  Many AGS functions use/return small negative and positive numbers and there is potential for conflict and confusion.  

The next thing to do is to define a variable to hold the gate's current state. We do thisbyentering the following in the script file. Because it defined is outside the bounds of a function definition it will maintain it's value throughout the game. In addition it's value will be save/restored by the save game mechanism.
   // gate's current state 
   int gate_state = CLOSED;

Next we will create our own function that will operate the gate.  We begin the function definition by typing the following:
   // Operate gate function 
   function OperateGate() {
   }

We want this function to open the gate if it's closed and close it if it's open. So we need to add an if-else construct as shown below.  Each time the function is executed it will toggle the state of the gate.
   // Operate gate function 
   function OperateGate() {
      // if the gate is open then close it ...
      if (gate_state == OPENED) {
                                       // repeat=0, direction=1, blocking=1
          // set gate's current state 
         gate_state = CLOSED;
      }
   
      // otherwise open it
      else {
                                       // repeat=0, direction=0, blocking=1
          // set gate's current state 
         gate_state = OPENED;
      }
   }

Now we can add gate sounds when it opens or closes.  We may as well enable and disable the walkable area under the gate's threshold also. This prevents the characters from walking through a closed gate.
   // Operate gate function 
   function OperateGate() {
      // if the gate is open then close it ...
      if (gate_state == OPENED) {
         //Play sound of gate closing
         PlaySound(1);      // sound1.wav

         // Prevent characters rom walking through closed gate
         RemoveWalkableArea(1);   // area-1 is under gate threshold

          // set gate's current state 
         gate_state = CLOSED;
      }
   
      // otherwise open it
      else {
         //Play sound of gate opening
         PlaySound(2);      // sound2.wav

         // Prevent characters rom walking through closed gate
         ReStoreWalkableArea(1);   // area-1 is under gate threshold

          // set gate's current state 
         gate_state = OPENED;
      }
   }

Finally we can add the animation of the gate as shown below.  One last thing; we have to call our function from an event handler.  This is done via the OperateGate(); statement in function object0_a().
   // text script for room

   // define some constant values
   #define OPENED -1000
   #define CLOSED -1001

   // gate's current state 
   int gate_state = CLOSED;

   // Operate gate function 
   function OperateGate() {
      // if the gate is open then close it ...
      if (gate_state == OPENED) {
         //Play sound of gate closing
         PlaySound(1);      // sound1.wav

         // Prevent characters rom walking through closed gate
         RemoveWalkableArea(1);   // area-1 is under gate threshold

         // Assign an animation loop to object, loop has frames 0..6 
         SetObjectFrame(0,1,0,6);   // object=0, view=1, loop=0, frame=6

         // Animate the gate
         AnimateObjectEx(0,0,0,0,1,1); // object=0, loop=0, delay=0, 
                                       // repeat=0, direction=1, blocking=1
          // set gate's current state 
         gate_state = CLOSED;
      }
   
      // otherwise open it
      else {
         //Play sound of gate opening
         PlaySound(2);      // sound2.wav

         // Prevent characters rom walking through closed gate
         RestoreWalkableArea(1);   // area-1 is under gate threshold

         // Assign an animation loop to object, loop has frames 0..6 
         SetObjectFrame(0,1,0,0);   // object=0, view=1, loop=0, frame=0

         // Animate the gate
         AnimateObjectEx(0,0,0,0,0,1); // object=0, loop=0, delay=0, 
                                       // repeat=0, direction=0, blocking=1
          // set gate's current state 
         gate_state = OPENED;
      }
   }
   
   function object0_a() {
        // script for object0: Interact object
      OperateGate();
   }


That's all I can write for now.  I need a few minutes sleep before going to work this morning.  

SLaMgRInDeR

i have an idea that dosn't require script, have walkable area infront of the gate and walkable area behind the gate, when the character opens the gate an animation or somthing is played and the character ends up on the other side of the gate in the other walkable area. don't know if this will work, and you probably don't need it anymore anyway tho.

Scorpiorus

Wow, nice one Rick! Could it be a good idea to add it to the technical archive or a beginners help sticky thread so the tutorial wouldn't get lost?

~Cheers

Scummbuddy

Oh, yes. I had already planned that. I was just waiting for more responses, before anyone gets lost in looking for it.

Great job, btw.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

RickJ

#17
If AuroraBoy or someone else would like to draw a background and gate sprites I could take it a bit further.  I would make an example room and modify the tutorial to have more details, screenies, etc...  Any colaborators?


P.S.  Scumm, Thanks for the graphics you sent me at the end of last year.  I haven't had a chance tyo incorporate them into Bluster yet.  While I was away  my wife bought a new house and the my current client's CEO passed away.    I'll be back to normal soon and will  be releasing Bluster with your graphics shortly.  Thaks for y our contributions.

RickJ

[edit]
P.S. Again, I also have the tutorial in plain text format if that is of any use to anyone I will make it available.

Scummbuddy

I might just take you up on that gate/bg offer. I'll let you know within a few hours time. I have to study for an upcoming test, and If I have time, I'd love to help out.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Squinky

I could do it also, But as Scummy has claimed it first, I'll wait and see if he has time. Me, on the other hand, have more time than is healthy....So let me know if you need me. Also Rick, I'm still interested in doing Pirate Sprites for you, I just can't seem to figure out what you want. So, if you write me and tell me what you need, it'll be done asap.

SMF spam blocked by CleanTalk