Nat Budin and Dark Fiber
When a AGI game is first started:
For example,
You are in an old belfry. Dangling right in front
of your face is a tattered and frayed rope.
You want the rope to break after the player pulls it. There are several ways you can code this, as with any language, you are not locked into any one way of programming it.
You have a flag "fPulledRope", at the start of the game it is set to False. When the player types in "pull rope" you check to see if "fPulledRope" is False, and if it is, you can set it to TRUE and then say "the rope breaks." The next time the player tries to pull the rope, checking "fPulledRope" is set to True, you can say "Sorry, the rope is broken and you can't reach what is left of it dangling to pull it."
In that scenario a flag was good, as the rope only had two states, pulled and not pulled. What if you wanted the rope to break after the player had pulled it three times? Obviously a flag is not enough to hold 3 different states, so using a variable would be best.
A quick less technical recap on flags and variables, flags are good for storing single state items, on or off. Variables are good for counters and
multiple state items.
First off, we'll program something simple, such as using a message box to show numbers. We'll create a popup message box in the middle of the screen that has the contents of the variable 40.
We'll use AGI Studio and create a blank game, create the directory called test-01 and hit OK. Next click on the "LOGIC editor" icon.
In that LOGIC type
return();
and save it as LOGIC 0.
Now above that return we can put our code.
The code for our little problem is quite simple, you need one print statement, one goto, one if, and one quit. To find what these statements mean, look them up in the AGI Studio help file.
How did you go? A very easy exercise, I know. This is my solution.
1 |
inner_loop: |
2 |
print("%v40"); /* our message box command */ |
3 |
v40++; /* increment our variable */ |
4 |
if(v40!=255) { /* test our variable */ |
5 |
goto(inner_loop); /* jump if it's not 255 */ |
6 |
} |
7 |
|
8 |
quit(1); /* quit program */ |
9 |
return(); |
Ok, now that's done, I want you to make a copy of that example. Alter the code so that the message box closes after 1/2 a second. (HINT: Look up "special variables" in the AGI Studio help.)
Code:reset(f15); /* set message box to use timed closure */ inner_loop: v21=1; /* set message box to close after � second */ print("%v40"); v40++; if (v40!=255) { goto(inner_loop); } quit(1); return();
"Ok, No more sissy examples," I hear you cry! Right-o, how about something far more complex without being really complex? Try to code the scrolling credits of the Kings Quest 1 intro, obviously without the graphics of course. Still think it's easy? It is! It has some heavy use of variables though.
How did you do? (Without looking at the actual code from Kings Quest 1!!) This is my solution (there are others possible):
Code:#define speed v10 #define new_room f5 #define start_line 10 #define start_col 10 #define end_line 14 #define start_msg 20 #define end_msg 35 #define cur_line v40 #define cur_col v41 #define cur_msg v42 #define begin_msg v43 if (new_room) { speed=12; set.text.attribute(15,0); clear.lines(0,24,1); cur_line=start_line; cur_col=start_col; cur_msg=start_msg; begin_msg=cur_msg; } inner_loop: cur_msg=begin_msg; begin_msg++; if(begin_msg==end_msg){ begin_msg=start_msg; } cur_line=start_line; clear.text.rect(10,9,13,31,0); jump_01: display.v(cur_line, cur_col, cur_msg); cur_line++; /* increment message number, wrap if need be */ cur_msg++; if (cur_msg==end_msg){ cur_msg=start_msg; } /* we only want to print 4 lines of text */ if (cur_line<end_line){ goto(jump_01); } if (have.key()){ quit(1); } return(); #message 20 "" #message 21 "" #message 22 "" #message 23 " This is our test" #message 24 "example of a scrolly" #message 25 " in AGI LOGIC" #message 26 "" #message 27 "It is supposed to be" #message 28 " similar to the" #message 29 "Kings Quest 1 intro" #message 30 " scrolly credits" #message 31 "only better coz ours" #message 32 "wraps at the end of" #message 33 " the scroller! ^_^" #message 34 "" #message 35 ""
Top
You can help keep The Sierra Help Pages and its affiliates alive by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.Thank you.
The Sierra Help Pages | Sierra Game Help | Walkthroughs | Hints, Tips & Spoilers | Utilities | Links | SHP Forums | Search
© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.
�