 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Thu Dec 21, 2006 10:20 am Post subject: Question concerning NPC reference |
|
|
I would like to know how it is determined which copy of an NPC is which when they are placed using plotscripting. I believe that it is backwards. Suppose I have the following:
Code: | for(i,0,3),do
begin
create npc (9,i,i)
end
for(i,0,3),do
begin
write global ( (i+1), npcreference(9,i) )
end |
The first part of the code places four copies of npc 9 on the map at 00,11,22,and 33 (I'll just call the NPCs by these 'names'). If I am right in my thinking, then this code would put a reference to Mr. 33 in global 1, and then Mr. 22 in global 2, etc - that is to say, backwards of the order I placed them. If I wanted to store them in the same order I placed them, I would have to do this with the second 'for' loop:
Code: | for(i,3,0,-1),do
begin
writeglobal( (4--i), npcreference(9,i) )
end |
Is this all true? I am currently having a strange problem with a farily complicated script of mine where mysteriously, 2 of my NPCs are being lost track of, and I want to make sure I at least understand this part correctly. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Thu Dec 21, 2006 11:41 am Post subject: |
|
|
'plot:create NPC' actually creates NPC's starting with the largest available NPC instance, and counts down. This is intentional. But you should not ever have to worry about that. You do not need to use 'plot:NPC reference' in this script at all, just store the reference returned by create NPC. Like this:
Code: |
for(i,0,3),do
begin
write global( i+1, create npc (9,i,i) )
end
|
That way you do not need to care if the NPC references are allocated forward, backwards, or randomly (you should assume they are allocated randomly, because the current backwards allocation is not guaranteed to work the same way in future versions) |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Fri Dec 22, 2006 1:00 am Post subject: |
|
|
Thanks for the info and advice. I actually changed my script a fair deal, but with your suggestions in mind.
I can't help but feel that this way of labelling different copies of NPCs feels somewhat counter-intuitive. For people who want to store the positions of, say, 10 copies of an npc at a time, they are going to want to use for loops. If they do this very often, on many different maps, they will be using a lot of globals. It would be better if they did not need globals for the npc references, and that would mean (it seems to me) the need to cycle through references by copy number on the fly. It would seem more natural if the copy number of an NPC corresponded to 'when' it was placed. If you guys end up changing this sometime, I would recommend having npc copy numbers increase starting from the first NPC put in custom, then going through those in custom, and then the first NPC placed by plotscripting, and on through in the order that they are placed by the plotscript.
I haven't thought about it a lot though, and I'm guessing you guys had a pretty good reason for doing it your way, but when you said that you might change this in the future, I thought I'd give my two cents. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Fri Dec 22, 2006 8:51 am Post subject: |
|
|
msw188 wrote: | Thanks for the info and advice. I actually changed my script a fair deal, but with your suggestions in mind.
I can't help but feel that this way of labelling different copies of NPCs feels somewhat counter-intuitive. For people who want to store the positions of, say, 10 copies of an npc at a time, they are going to want to use for loops. If they do this very often, on many different maps, they will be using a lot of globals. It would be better if they did not need globals for the npc references, and that would mean (it seems to me) the need to cycle through references by copy number on the fly. It would seem more natural if the copy number of an NPC corresponded to 'when' it was placed. If you guys end up changing this sometime, I would recommend having npc copy numbers increase starting from the first NPC put in custom, then going through those in custom, and then the first NPC placed by plotscripting, and on through in the order that they are placed by the plotscript.
I haven't thought about it a lot though, and I'm guessing you guys had a pretty good reason for doing it your way, but when you said that you might change this in the future, I thought I'd give my two cents. |
The problem with assigning NPCs in order is that it can't be guaranteed. What about when you create 10 NPCs, then delete five, then create 10 more? Should the second ten fill in the empty slots deleted by the five you deleted? or should stey start aferward? What about when we reach the last slot, and have to cycle back to the beginning looking for empty slots?
Although a different NPC allocation order would make some scripts easier, those scripts would only work right *most* of the time, but under some conditions they might not work.
I agree that the need to store NPC references in globals is rather awkward, but it is a necessary evil.
Somtime in the future, we might have nice arrays that you can use as an alternative to read global and write global. Maybe something like:
Code: |
# This code is a hypothetical example. it will not work!
variable(i)
array(refs)
for(i, 1, 4) do, begin
refs[] := create NPC(9, i, i)
end
for(i, 0, array end(refs)) do, begin
walk NPC(refs[i], south, 3)
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
|