 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Sun Aug 31, 2003 7:59 am Post subject: Continuous script checking? |
|
|
I want a script in my game to be checked constantly, so I'm guessing I use WHILE, and DO statements but i'm not sure how to use them properly. I want my game to continously check this script...
script,my script,begin
if (heroX(me)==NPCX(2),and,heroY(me)==NPCY(2))
then (show text box (270))
wait for text box
end |
|
Back to top |
|
 |
Cube Dimensional Traveller

Joined: 02 Feb 2003 Posts: 294
|
Posted: Sun Aug 31, 2003 9:02 am Post subject: |
|
|
Considering what is going on in the script, you most likely won't have to use a while loop. My guess is that while the player is walking around, you want to check if he's on a specific spot. Particularily, where NPC #2 is.
So, if that's the case, all you have to do is throw that script into the "every step" script that you find in the general settings in each map (You know, it's the same place you set the map's music and stuff).
So, that ought to do it. If you need it to work in some other way, be sure to say it and I'll help you further. |
|
Back to top |
|
 |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Sun Aug 31, 2003 10:46 am Post subject: |
|
|
oh sorry I should have explained more. I have already tried that and the problem with that is the npcs in this script are moving, and also activated by "step on", so the script would only be called if the npc and hero were running "within" each other (if that makes sense).
I think I will need a while loop, just because both the npc's and the hero are moving. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun Aug 31, 2003 1:57 pm Post subject: |
|
|
Well.. since you need to know how to make for loops anyway:
Code: |
while (*condition*) do, begin
if (heroX(me)==NPCX(2),and,heroY(me)==NPCY(2))
then (show text box (270))
wait for text box
end
|
This will loop while the condition is true. If you want it to loop forever, use (true). However, this will loop FOREVER (well, actually, only only until the player quits and loads their game), and will give you a warning. Otherwise use
while (current map == 4) do, begin
etc _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Mon Sep 01, 2003 12:48 am Post subject: |
|
|
ok, here is my script now:
script,my script,begin
while (current map == 5) do, begin)
if (heroX(me)==NPCX(2),and,heroY(me)==NPCY(2))
then (show text box (270))
wait for text box
end
but their is a problem, whenever I load up my game the screen remains blank? My game is saved on map 5, is this a problem or does it have to do with looping? By the way, what I'm trying to do is just make a script run when the npc and hero are on the same tile, normally i'd use "step on", but this doesnt work when both npcs and the hero are moving, if theres any easier way to do this i'd be happy to hear. |
|
Back to top |
|
 |
djfenix

Joined: 12 Mar 2003 Posts: 359
|
Posted: Mon Sep 01, 2003 12:53 am Post subject: |
|
|
You have an extra ")"
script,my script,begin
while (current map == 5) do, begin ) #right here
if (heroX(me)==NPCX(2),and,heroY(me)==NPCY(2))
then (show text box (270))
wait for text box
end |
|
Back to top |
|
 |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Mon Sep 01, 2003 10:27 am Post subject: |
|
|
I dont think thats the problem, I only added that in after it wouldnt allow me to compile saying "script my script is missing end or ) |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Mon Sep 01, 2003 11:14 am Post subject: |
|
|
You forgot the end for the script. Loops Need beginnings and ends just like anythign else. My fault, I confised you by only copying the piece of code in the middle. Heres your script:
Code: |
script,my script,begin
while (current map == 5) do, begin
if (heroX(me)==NPCX(2), and, heroY(me)==NPCY(2))
then (show text box (270))
wait for text box
end
end
|
_________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Wed Sep 03, 2003 1:48 am Post subject: |
|
|
ok thanks everyone, I've got it working for npc 2 now, but there are 7 others I still need to script. I though I'd just do this, but some of the npcs aren't triggering anything at all, where as some are:
script,my script,begin
while (current map == 5) do, begin
if (heroX(me)==NPCX(2),and,heroY(me)==NPCY(2))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(3),and,heroY(me)==NPCY(3))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(5),and,heroY(me)==NPCY(5))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(6),and,heroY(me)==NPCY(6))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(7),and,heroY(me)==NPCY(7))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(8),and,heroY(me)==NPCY(8))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(9),and,heroY(me)==NPCY(9))
then (show text box (270))
wait for text box
if (heroX(me)==NPCX(11),and,heroY(me)==NPCY(11))
then (show text box (270))
wait for text box
end
end
is the script the problem or is it something else? |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Wed Sep 03, 2003 2:25 am Post subject: |
|
|
Your "wait for text box" commands belong inside the "then" bocks.
You should also have a "wait(1)" at the end of the "while" loop
Code: |
script,my script,begin
while (current map == 5) do, begin
if (heroX(me)==NPCX(2),and,heroY(me)==NPCY(2))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(3),and,heroY(me)==NPCY(3))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(5),and,heroY(me)==NPCY(5))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(6),and,heroY(me)==NPCY(6))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(7),and,heroY(me)==NPCY(7))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(8),and,heroY(me)==NPCY(8))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(9),and,heroY(me)==NPCY(9))
then (show text box (270),wait for text box)
if (heroX(me)==NPCX(11),and,heroY(me)==NPCY(11))
then (show text box (270),wait for text box)
wait(1)
end # end of while
end # end of script
|
Also, this is a perfect candidate for an autonumbered script, so you might want to write the script like this, if it looks cleaner to you (but if it doesn't make it any easier for you to read,then don't bother, because it isn't going to run faster or better or anything):
Code: |
define script (autonumber,check NPC collision, 1, 0)
script, check NPC collision, NPC, begin
if (heroX(me)==NPCX(NPC),and,heroY(me)==NPCY(NPC))
then (show text box (270),wait for text box)
end
script,my script,begin
while (current map == 5) do, begin
check NPC collision(2)
check NPC collision(3)
check NPC collision(5)
check NPC collision(6)
check NPC collision(7)
check NPC collision(8)
check NPC collision(9)
check NPC collision(11)
wait(1)
end # end of while
end # end of script
|
|
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Wed Sep 03, 2003 2:31 am Post subject: |
|
|
Another thought. using NPC ID's is pretty slow. If this script runs too slow for you, cache NPC references in local script variables like this:
Code: |
define script (autonumber,check NPC collision, 1, 0)
script, check NPC collision, NPC, begin
if (heroX(me)==NPCX(NPC),and,heroY(me)==NPCY(NPC))
then (show text box (270),wait for text box)
end
script,my script,begin
variable(ref2,ref3,ref5,ref6,ref7,ref8,ref9,ref11)
ref2:=NPC reference(2)
ref3:=NPC reference(3)
ref5:=NPC reference(5)
ref6:=NPC reference(6)
ref7:=NPC reference(7)
ref8:=NPC reference(8)
ref9:=NPC reference(9)
ref11:=NPC reference(11)
while (current map == 5) do, begin
check NPC collision(ref2)
check NPC collision(ref3)
check NPC collision(ref5)
check NPC collision(ref6)
check NPC collision(ref7)
check NPC collision(ref8)
check NPC collision(ref9)
check NPC collision(ref11)
wait(1)
end # end of while
end # end of script
|
it looks kinda ugly and confusing, but it will be signifigcantly faster, because it only needs to locate the NPC's once, not re-locate them for every single cycle of the "while" |
|
Back to top |
|
 |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Wed Sep 03, 2003 3:30 am Post subject: |
|
|
Being new to coding, i understand that vaguely... and I used it in my script and I still have the same problem. The script will only run on the first npc you encounter (#2 in this case), so there is one copy of npc 2 that works fine, but as you encounter all the other different npcs nothing is triggered. I dont have any idea what to do so maybe i'll abort this. But if it means anything, text box 270 has a script running next after it. I wish I knew what I was doing, this is probably so simple. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sat Sep 06, 2003 5:19 am Post subject: |
|
|
Script triggered? That might be it. Explain what the script does... _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Awful Waffle
Joined: 18 Jun 2003 Posts: 73 Location: Canada
|
Posted: Sat Sep 06, 2003 6:30 am Post subject: |
|
|
here is the script following textbox 270, if you can't find a problem don't worry about it, i'm working around this...
script,text270script,begin
suspend player
show text box (271)
wait for text box
fade screen out (63,63,0)
fade screen in
set hero position (me,11,44)
set hero direction (me,up)
wait for hero (me)
show text box (272)
wait for text box
resume player
end |
|
Back to top |
|
 |
Flamer The last guy on earth...

Joined: 04 Feb 2003 Posts: 725 Location: New Zealand (newly discovered)
|
Posted: Sun Sep 07, 2003 12:11 pm Post subject: |
|
|
Code: | script,text270script,begin
suspend player
show text box (271)
wait for text box
fade screen out (63,63,0)
fade screen in
set hero position (me,11,44)
set hero direction (me,up)
wait for hero (me)
show text box (272)
wait for text box
resume player
end |
from what can get from this...
textbox 271 displays
the screen flashes
hero then teleports to (11,14)
and textbox 272 displays.
you don't need the "wait for hero" since the hero isn't wlking, and is instantly transported to (11,14)
what mistakes or better yet, what do you want this to do?
are you sure you want to fade screen in straight after a fade screen out??
wouldn't it be a better idea to have it like this...
Code: | fade screen out (63,63,0)
set hero position (me,11,44)
set hero direction (me,up)
fade screen in |
_________________ 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 |
|
 |
|
|
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
|