
12-29-2001, 02:56 AM
|
|
Registered User
|
Join Date: Dec 2001
Location: Corpadverticus, which in case you don't know is the recently-formed and Blockbuster Video-sponsored Tenth Circle of Hell
Posts: 57
|
|
|
I find keydowns work best in a while loop. This example is commented through for you:
if (playerenters){
// Sets image to shoes.gif
setimg shoes.gif;
}
if (playertouchsme){
// Adds weapon to player weapons
toweapons Skip Wall Boots;
}
if (weaponfired && !working){
sleep 0.05;
set working;
// Sets flag to make system work.
// For some strange reason Graal
// requires a sleep command if
// you're turning flags on and off.
}
if (weaponfired && working){
sleep 0.05;
unset working;
// Unsets flag; disables NPC
}
while (working){
// Oh boy, long bit... if a movement key
// is pressed, the player moves faster
// than normal and can walk through
// walls.
if (keydown(0)){
players[0].y=players[0].y-1;
}
if (keydown(1)){
players[0].x=players[0].x-1;
}
if (keydown(2)){
players[0].y=players[0].y+1;
}
if (keydown(3)){
players[0].x=players[0].x+1;
}
sleep 0.05;
// To keep the loop stable and running,
// a sleep 0.05 or sleep 0.1 should always
// be added at the end of any while
// statement
}
Just as a little background here, remember the longest a Graal script can reasonably pause for is 0.05 of a second, or 1/20 of a second. Smaller increments force the while loop to do 10,000 operations in roughly .1 of a second, slowing down your Graal program and also freezing the script, as while-s without a sleep command can only run 10,000 times.
Or here's your NPC back edited accordingly:
if (playerenters) {
setimg shoes.gif;
// or you can replace this with whatever image
// you want it to be
}
if (playertouchsme) {toweapons automatic test;
}
while (isweapon){
if (keydown(6)){
putleaps 0,playerx,playery;timeout=0.5;
}
sleep 0.05;
}
Your NPC will now put grass explosions at your player's co-ordinates while the player has the weapon and while the key for lifting items is pressed. See? |
__________________
AIM: GrowlZ1010 | Y! IM: GrowlZ1010 | MSN: [email protected] | Email: [email protected]
- I use obscenely long words to befuddle my adversaries, therefore I am -
Current Favorite Quote: Real programmers don't document. If it was hard to write, it should be hard
to understand.
|
|
|
|