 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Dan the Man Entertainment
Joined: 31 May 2003 Posts: 204
|
Posted: Fri May 28, 2004 6:42 am Post subject: Sword script that works ALMOST perfectly........ |
|
|
Recently, I've started on a Zelda-style game where you use a sword. I've gotten the sword to work almost perfectly like the sword in The Legend of Zelda (the first one). Only problem is, the instant the sword reaches it's
destination, the game freezes. This is weird! I have no idea what would cause the game to freeze over a little script like this one. Can anyone help me?
Here's the script:
Code: |
script, rightslash, sword, begin
set hero picture (me, 3, outside battle)
variable (hitnpc)
set variable (sword, npcreference(0))
set variable (sdx, herox(me)+1)
set variable (sdy, heroy(me))
set variable (sd, herodirection (me))
create npc (sword, herox(me), heroy(me), sd)
walknpc to x (sword, sdx)
walknpc to y (sword, sdy)
wait for npc (sword)
while (activesword==true) do(
set variable (sx, npcx(sword))
set variable (sy, npcy(sword))
)
for (hitnpc, 1, 35) do(
if (npcx(hitnpc)==sx,and,npcy(hitnpc)==sy)then(
set variable (target, npc at spot (sx, sy))
damage
tweak palette(64,64,64)
update palette
wait (2)
reset palette
update palette
)
)
wait (5)
set variable(activesword, false)
destroynpc (sword)
set hero picture (me, 0, outside battle)
resume player
end
|
That's just the script for the east-direction sword attack. The others work in the same way and have the same effect. |
|
Back to top |
|
 |
Guest
|
Posted: Fri May 28, 2004 7:44 am Post subject: |
|
|
There could be a tile offset somewhere... not too sure though.It happend to me in Winterfold. When I made the Eagle spirit too fast for the tiles and the character was caught inbetween one and another.
Hope you find the problem... sword scripts are cool... if you pull it off, you are a legend.  |
|
Back to top |
|
 |
rpgspotKahn Lets see...

Joined: 16 May 2004 Posts: 720 Location: South Africa
|
Posted: Fri May 28, 2004 7:46 am Post subject: |
|
|
By the way ^^ thats me up there ^^
Forgot to log in  _________________
2nd Edition out now! |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri May 28, 2004 5:04 pm Post subject: |
|
|
Your script will freeze upon reaching
Code: |
while (activesword==true) do(
set variable (sx, npcx(sword))
set variable (sy, npcy(sword))
)
|
if 'active sword' is true. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Dan the Man Entertainment
Joined: 31 May 2003 Posts: 204
|
Posted: Fri May 28, 2004 5:42 pm Post subject: |
|
|
Please don't tell me it's because I stupidly left out the "wait(1)" for the
loop. |
|
Back to top |
|
 |
Ysoft_Entertainment VB Programmer

Joined: 23 Sep 2003 Posts: 810 Location: Wherever There is a good game.
|
Posted: Fri May 28, 2004 7:07 pm Post subject: |
|
|
here is a simple rule, while always must have the wait(1) command
doesn't matter what you you it for, the first statement after while ()do() must always be wait(1)(not sure why though, a bug maybe, or maybe its the way James programmed the while loop) _________________ Try my OHR exporter/importer.
OHRGFX
Striving to become better pixel artist then Fenrir Lunaris. Unfortunately the laziness gets in the way of my goals. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sat May 29, 2004 1:49 am Post subject: |
|
|
NO! EVIL FALLACY!!
While loops do not require 'wait' statements, it is just that in many uses of them, a wait is required. But people have picked up the reasoning that game.exe will freeze if while is missing a wait, this is not the case. Hence plotscriptors like to throw wait statements in all over the place where they are not needed, leading to large delays in some scripts.
But yes, I think you left out a wait in your script. Provided that other scripts are using sx and sy, otherwise sticking the set variables in the while loop is pointless.
An exam of a while loop not requiring wait:
Code: |
script, next square, n, begin
variable (num)
while (num ^ 2 << n) do (increment (num))
return (num ^ 2)
end
|
Aother, non-computation, example: (flow control)
Code: |
script, main, begin
variable (branch to)
branch to := 1
while (branch to <> 0) do (
if (branch to == 1) then (branch to := intro)
if (branch to == 2) then (branch to := world map)
if (branch to == 3) then (branch to := level one)
if (branch to == 4) then (branch to := level two)
)
end
script, intro, begin
...
return (2)
end
script, world map, begin
...
if (...) then (return (3))
if (...) then (return (4))
end
script, ...
|
As for an example where wait is required:
Code: |
while (key is pressed (key: space) == 0, and, key is pressed (key: enter) == 0) do (
#create a cool animation out of several npcs
put npc (...
...
wait
)
|
When you need a wait command:
To create a pause
When you need to update player input (key is pressed), or game.exe will never notice if a key is pressed
When you want a change to affect the game, e.g. use door, show backdrop, put hero
To allow game.exe to do things like automatically moving npcs and animating tiles. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Dan the Man Entertainment
Joined: 31 May 2003 Posts: 204
|
Posted: Sat May 29, 2004 10:00 am Post subject: |
|
|
Thanx. I tried the wait for the loop, but it still has the same effect. It doesn't matter anyway because I almost completely re-wrote the script and made it (yes) PERFECT. Speaking of whiles without waits, would I need a wait (1) for:
A) A health bar
B) A condition if the sword hits the enemy (implemented into the enemy's script)
C) A script that creates an enemy projectile |
|
Back to top |
|
 |
Flamer The last guy on earth...

Joined: 04 Feb 2003 Posts: 725 Location: New Zealand (newly discovered)
|
Posted: Sat May 29, 2004 4:33 pm Post subject: |
|
|
all of them depend on how you script it...
health bar: if you're continuously checking, while the game is playing, then yes you do.
sword hits enemy: i'd say so, but shouldn't this script be an if statement inside your enemy AI while loop...? i dunno, try it without the wait(1), if it freezes then change it. it's all part of your debugging experience.
enemy projectile:
creating: possibly, again... depends on how you script things out.
moving: most definately, this is where people stump and are forced to think that every while loop needs a wait(1) in it.
i do agree with TMC that it is annoying how people keep thinking the wait(1) is manditory with while loops.
i always see a while loop as a continuous repeat of a command, and the only reason i'll need a wait(1) in it, is because (a) i need the player to move while the script is running (b) it's a long series of something i want the player to see.
i do not add wait(1) to a while loop, becasue (c) i want everything in the while loop to be done "instantly", and the condition for the while loop will end without the player doing anything. _________________ If we were a pack of dogs, IM would be a grand Hound, CN would be a very ficious little pitball, and Giz...well, it doesn't matter breed he is, he'd still be a bitch
(no offense to anyone that was mentioned) |
|
Back to top |
|
 |
Dan the Man Entertainment
Joined: 31 May 2003 Posts: 204
|
Posted: Sat May 29, 2004 6:37 pm Post subject: |
|
|
Thanx. Now my last and final (or should I just say "Zetton") problem:
When I use the sword on an enemy, it doesn't quite work. It works about 3 seconds later. I have it in the enemy script so when the X and Y coordinates of the sword hit them, the screen flashes white and their health is depleted. This works either slowly, or not at all.
On a side note, you do need a wait(1) for health scripts. Without them, they just don't work. |
|
Back to top |
|
 |
Flamer The last guy on earth...

Joined: 04 Feb 2003 Posts: 725 Location: New Zealand (newly discovered)
|
Posted: Sat May 29, 2004 8:52 pm Post subject: |
|
|
health scripts vary from system to system. some do, some definately don't.
look at where you are calling the checking script to see whether the sword has hit or not, if it's too far back, it'll definately lag behind.
also, the reason that it happens 3 seonds later or not at all, i'm guessing is because it's not checking it's pixel X and Y co-ordinates, but it's tile X and Y co-ordinates...
i'm only guessing, but that seems likely to be the case _________________ If we were a pack of dogs, IM would be a grand Hound, CN would be a very ficious little pitball, and Giz...well, it doesn't matter breed he is, he'd still be a bitch
(no offense to anyone that was mentioned) |
|
Back to top |
|
 |
Dan the Man Entertainment
Joined: 31 May 2003 Posts: 204
|
Posted: Sat May 29, 2004 9:45 pm Post subject: |
|
|
OK,
I don't understand pixel X or pixel Y at all, but I would think that it would be the answer to my prayers. Does the pixel X and Y mean the pixels on the npc that aren't transparent, or is it something else that I don't understand? |
|
Back to top |
|
 |
Flamer The last guy on earth...

Joined: 04 Feb 2003 Posts: 725 Location: New Zealand (newly discovered)
|
Posted: Sun May 30, 2004 3:57 am Post subject: |
|
|
yeah, something like that.
it's not very easy for me to explain, because i haven't actually tried pixel movement in a large scale script. _________________ If we were a pack of dogs, IM would be a grand Hound, CN would be a very ficious little pitball, and Giz...well, it doesn't matter breed he is, he'd still be a bitch
(no offense to anyone that was mentioned) |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Mon May 31, 2004 10:39 pm Post subject: |
|
|
Dan the Man Entertainment wrote: | OK,
I don't understand pixel X or pixel Y at all, but I would think that it would be the answer to my prayers. Does the pixel X and Y mean the pixels on the npc that aren't transparent, or is it something else that I don't understand? |
pixel X and pixel Y have nothing to do with transparency.
Nomrally you get and set the hero's position in terms of tiles. So if the hero is in the top left of the map:
hero X == 0, and, hero Y == 0
And if you walk three tiles to the right;
hero X == 3, and, hero Y == 0
and then you walk two tiles down, and;
hero X == 3, and, hero Y == 2
and then you want to walk half a tile left, but... what? You can't walk by half tiles! That is where pixel position comes in.
If your hero is in the top left corner of the map,
hero pixel X == 0, and, hero pixel Y == 0
and you walk three tiles to the right. Remember that each tile is 20x20 pixels;
hero pixel X == 60, and, hero pixel Y == 0
and then you walk two tile down;
hero pixel X == 60, and, hero pixel Y == 40
And if you walk one tile left you measure your position halfway between tiles, you might get;
hero pixel X == 50, and, hero pixel Y == 40
but when the move finishes, you will always be aligned with the tiles again, so your pixel position will be divisible by 20
hero pixel X == 40, and, hero pixel Y == 40
In a plotscript that does not confine the hero to the grid, you can do movement entirely with "hero pixel X" "hero pixel Y" and "put hero" and NEVER use the "walk hero" or "wait for hero" commands at all.
Here is a simple example:
Code: |
# walk one tile down normally
walk hero (me,south,1)
wait for hero (me)
# walk one tile down without using the normal commands
set hero direction (me,south)
variable(loop)
for (loop,1,5), do, begin
put hero(me,get hero pixel X,get hero pixel Y(me)+4)
wait (1)
end
|
|
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|