Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Help with a script

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Meatballsub
Divine Bovine




Joined: 16 Jun 2003
Posts: 437
Location: Northwest Georgia

PostPosted: Mon Jun 02, 2008 9:16 am    Post subject: Help with a script Reply with quote

What I am trying to accomplish here is making a script that makes you press a key to start it, then it randomly picks from a couple of sequences to follow.

One of the sequences merely shows a text box and starts the script over while the other sequence is supposed to set a five second timer and make you press a key as many times as possible. When the timer is up, it is supposed to check a variable and do something depending on the results.

However, all that happens when the timer starts is a hard lock in-game. Any suggestions?

Also, if you know of a way to add a feature within this script that allows the player to exit the script that would be nice. The whole script is supposed to repeat itself over and over again.

Be warned my scripting skills are terrible, which is why this probably doesn't work in the first place.

Code:
script,Blah,begin
suspend npcs
teleport to map (76,3,5)
set hero direction (0,south)
show textbox (989)
wait for textbox
wait for scancode (46)

variable (x)
x:=2

while (x<<4) do (
create npc (1,3,6)
variable (r)
r := random(0, 1)
if (r == 0) then (
set npc direction (1,left)
wait for npc (1)
show textbox (990)
wait for textbox
variable (feet)
set timer (0,5,1,timer:default)
while (read timer (0>0)) do (
if (key is pressed(19== true)) then (
feet+=1
) )
if (read timer (0==0) and (feet >= 5)) then (
show textbox (992))
else ( show textbox (993))

destroy npc (1)
if (r == 1) then (
show textbox (991)
wait for textbox
destroy npc (1)
) ))
end
Back to top
View user's profile Send private message Visit poster's website
Camdog




Joined: 08 Aug 2003
Posts: 606

PostPosted: Tue Jun 03, 2008 5:48 am    Post subject: Reply with quote

The first thing that jumps out at me is that your parentheses are placed incorrectly when you're checking the timer values. Things in parentheses are always evaluated first. For example, a statement like:

Code:
read timer(myTimer + 1)


would check the value of the timer with the id myTimer + 1, rather than checking the value of the timer myTimer and then adding 1 to it. So, your statement:

Code:
while (read timer(0>0)) do (


checks to see if the value at timer(false) evaluates to true (since 0 is not greater than 0, it evaluates to false before the read timer function is called), rather than checking to see if the value at timer 0 is greater than 0. I believe false evaluates to 0 in hamsterspeak, which means you're checking timer 0, which is fine, but you're skipping the greater than condition you want. Since the timer is incrementing, and (I believe) positive integers are always equivalent to true, reade timer(0>0) is always true, and therefore you have an infinite loop, which would explain your lock. Try:

Code:
while (read timer(0)>0) do (


to see if that fixes it. Remember to also change:

Code:
if (read timer (0==0) and (feet >= 5)) then (


to:

Code:
if ((read timer (0)==0) and (feet >= 5)) then (


Also, it looks as if you're setting the trigger value of your timer to default. It seems timers were designed to fire off a custom script when they finish executing, and the documentation doesn't make it clear what happens if you just give that argument a default value. So, that may also cause you problems, in which case you might want to create a trigger script that just increments a global variable, and have your while statement check that instead of the number of ticks elapsed on the timer.
Back to top
View user's profile Send private message
Meatballsub
Divine Bovine




Joined: 16 Jun 2003
Posts: 437
Location: Northwest Georgia

PostPosted: Tue Jun 03, 2008 6:46 pm    Post subject: Reply with quote

I changed a few things around, but i'm still getting a hard lock if it goes to sequence one. Here is the updated code:

Code:
script,blah,begin
suspend npcs
suspend player
teleport to map (76,3,5)
set hero direction (0,south)
resume player
show textbox (989)
wait for textbox
wait for scancode (46)
set hero picture ((find hero(0)),99,outside battle)
create npc (1,3,6)
wait (50)
variable (r)
r := random(0, 1)
if (r == 0) then (
set npc direction (1,left)
wait for npc (1)
show textbox (990)
wait for textbox
variable (feet)
set timer (0,5,18,timer:default)
while (read timer (0)>>(0)) do (

if (key is pressed(19== true)) then (
feet+=1

if ((read timer (0)==(0)) and (feet >= 5)) then (
show textbox (992)
wait for textbox
destroy npc (1)
else ( show textbox (993)

) ))

if (r == 1) then (
show textbox (991)
wait for textbox
destroy npc (1)
) ))
end
Back to top
View user's profile Send private message Visit poster's website
Meatballsub
Divine Bovine




Joined: 16 Jun 2003
Posts: 437
Location: Northwest Georgia

PostPosted: Wed Jun 04, 2008 5:57 am    Post subject: Reply with quote

Camdog, if I did not do something exactly how you suggested, know it is because I suck at scripting, not that I am ignoring your suggestions Happy
Back to top
View user's profile Send private message Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Thu Jun 05, 2008 7:13 am    Post subject: Reply with quote

How can you expect anyone to understand your script when you've purposefully obfuscated it with terrible formatting? A little bit of indentation ges a long way to spotting mistakes:

SO LEARN TO INDENT!
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Meatballsub
Divine Bovine




Joined: 16 Jun 2003
Posts: 437
Location: Northwest Georgia

PostPosted: Thu Jun 05, 2008 9:15 am    Post subject: Reply with quote

I would have gladly formatted it different if I knew it was so unbearable, but out of the many scripts I have posted for help on here, this is the only one that has been complained about.

I apologize dude.
Back to top
View user's profile Send private message Visit poster's website
Meatballsub
Divine Bovine




Joined: 16 Jun 2003
Posts: 437
Location: Northwest Georgia

PostPosted: Thu Jun 05, 2008 11:05 am    Post subject: Reply with quote

Script has been resolved.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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