 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
sheamkennedy

Joined: 06 May 2013 Posts: 23 Location: Canada
|
Posted: Thu Sep 26, 2013 2:31 pm Post subject: I need some help finding the issue with this script |
|
|
I'm attempting to make a line of sight script for my game such that if you enter the 'sight' of an enemy NPC they will be alerted and chase your character.
So far I have made a script that shoots out a sequence of 'invisible sight NPCs' the the west of the 'guard NPC.' For the sake of making my script easy to debug I have actually made these 'sight NPCs' visible in the game testing so I could see just exactly what's happening.
The problem I'm having:
I specifically made my script as a 'while' script so that while the 'guard NPC' is facing in the west direction the Line of Sight will be carried out. You can see in the video provided that the 'guard NPC' starts out facing west and all goes well. But if the NPC is turned another direction and then back to the westward direction that the script does not continue to work. Can anyone tell me why this is? It may be important to note that this script is being run as an Autorun Script for the map
Here's the script thus far:
Code: |
global variable (0, x)
global variable (1, y)
#--------------------LINE OF SIGHT--------------------------
plotscript, Line Of Sight, begin
x := hero x (find hero (0))
y := hero y (find hero (0))
variable (xNPC, yNPC, z)
xNPC := NPC X (0)
yNPC := NPC Y (0)
z := 1
#Line of sight sweep for west-facing NPC
While (NPC direction (0) == west) do(
#Line of sight point west
#####
If (read zone (10, xNPC--1, yNPC) == true) then(
break
)
else (
create NPC (1, xNPC--1, yNPC, west)
wait (1)
destroy NPC (1)
wait (1)
)
#####
If (read zone (10, xNPC--2, yNPC) == true) then(
break
)
else (
create NPC (1, xNPC--2, yNPC, west)
wait (1)
destroy NPC (1)
wait (1)
)
#####
If (read zone (10, xNPC--3, yNPC) == true) then(
break
)
else (
create NPC (1, xNPC--3, yNPC, west)
wait (1)
destroy NPC (1)
wait (1)
)
#####
If (read zone (10, xNPC--4, yNPC) == true) then(
break
)
else (
create NPC (1, xNPC--4, yNPC, west)
wait (1)
destroy NPC (1)
wait (1)
)
#####
If (read zone (10, xNPC--5, yNPC) == true) then(
break
)
else (
create NPC (1, xNPC--5, yNPC, west)
wait (1)
destroy NPC (1)
wait (1)
)
#####
#May need to add an additional break and/or wait here...
#wait (30)
#destroy NPC (1)
#wait (30)
)
end
|
And the video of this issue can be seen here:
[url]
http://www.youtube.com/watch?v=A4DvThX7ui8&list=SP-ywmUILu1tgN7OJ_KDFM2wZOqoSoxvid
[/url] _________________ SMK |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Thu Sep 26, 2013 11:36 pm Post subject: |
|
|
If the NPC turns to face a direction other than west, then the while loop exits, causing the whole script to exit.
Why are you creating NPCs in front of the NPC? Are they on-touch, to detect whether the player is there?
This isn't a good way to write a line-of-sight script. Instead, have a look at the 'scripts:line of sight' article.
Also, "x := hero x (find hero (0))" is wrong. "hero x" takes a caterpillar party slot, not a battle party slot. The correct version is x := hero x(0), since the leader is always in the first caterpillar slot. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
sheamkennedy

Joined: 06 May 2013 Posts: 23 Location: Canada
|
Posted: Fri Sep 27, 2013 8:07 am Post subject: |
|
|
TMC wrote: | Why are you creating NPCs in front of the NPC? Are they on-touch, to detect whether the player is there?
|
The reason for these NPC's out front of the guard NPC is only so I can see how my line of sight is propagating from the guard NPC.
I read through the Line of Sight Script Wiki that you linked me to. I had read through it earlier and didn't fully understand it so I decided to make my own script so I could understand what was going on and so I could customize the shapes of my line of sight later on.
I'm know the NPC step-on activation would likely prove very faulty for making a line of sight script. As far as I can tell the Line of Sight Script Wiki is alternatively comparing the hero's X-Y with the guard's sight X-Y... Is this correct? This is kind of what I planned on doing.
Quote: | Also, "x := hero x (find hero (0))" is wrong. "hero x" takes a caterpillar party slot, not a battle party slot. The correct version is x := hero x(0), since the leader is always in the first caterpillar slot. |
In my Line of Sight script I will eventually want to make the script so that the enemy is not only able to sight the party leader but also the other hero's that follow along in my caterpillar party. So would it then be best if I used:
x := hero x(0)
a := hero x(1)
c := hero x(2)
e := hero x(3)
y := hero y(0)
b := hero y(1)
d := hero y(2)
f := hero y(3) ....
This would keep track of the (x,y) of each position of the caterpillar such that if any portion of the caterpillar entered the enemies line of sight that the player would be 'caught?'
Thanks _________________ SMK |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Fri Sep 27, 2013 8:43 am Post subject: |
|
|
That definitely sounds like a job for a "for" loop |
|
Back to top |
|
 |
sheamkennedy

Joined: 06 May 2013 Posts: 23 Location: Canada
|
Posted: Fri Sep 27, 2013 10:36 am Post subject: |
|
|
Bob the Hamster wrote: | That definitely sounds like a job for a "for" loop |
So then I'd use the 'for' loop for comparing my party members (x,y) positions with the Enemy's sight (x,y) which is constantly scanning for me and then if any of my hero's entered the sight range they would be 'seen'... and some other event would be triggered, like the enemy NPC would be set to chase?
I'm assuming since the script is checking the enemy sight (x,y) positions so fast that even though it's cycling through the enemy's sight range it should still catch my hero when they enter. And even if it doesn't I suppose I could always avoid this problem by comparing all the prior enemy sight (x,y) positions at the same time as the new ones once those positions are determined to be unobstructed by walls. _________________ SMK |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Mon Sep 30, 2013 12:01 am Post subject: |
|
|
I'm just going to say that your post suggests that you think that scripts run concurrently with the rest of the engine, which isn't true.
http://www.slimesalad.com/forum/viewtopic.php?t=5870
If you're still confused about how scripting works, ask.
Note, the script in the article I linked to is very complicated, but it links to another simplified version which you should look at for educational purposes. _________________ "It is so great it is insanely great." |
|
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
|