 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Camdog
Joined: 08 Aug 2003 Posts: 606
|
Posted: Thu Nov 13, 2008 2:06 pm Post subject: Quick Question about NPC References |
|
|
Can they change during the course of a game? Specifically, if I 'destroy npc' one of my NPCs, is it possible that would change the reference numbers of the other NPCs on the map of the same ID? That appears to be the behavior in custom, and there are some strange things that happen in some of my projects that would be explained by this.
If this is the case, is there way around this? Any permanent reference I can get to an NPC copy that will always be accurate? |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Thu Nov 13, 2008 2:11 pm Post subject: |
|
|
What are you doing specifically? I haven't done anything that kept track of NPC refs for awhile, but it's been my experience that they don't change.
Regardless, you may be better off using npc reference(id, count) instead of storing the reference locally. _________________
|
|
Back to top |
|
 |
Camdog
Joined: 08 Aug 2003 Posts: 606
|
Posted: Thu Nov 13, 2008 3:16 pm Post subject: |
|
|
I'm storing a series of bullets in a list, which grows upon the addition of new bullets, and destroys the bullet and removes the corresponding list item when the bullet moves out of bounds.
In the game loop, I iterate through the list, moving and disposing of the bullets as needed.
The list code works dandy when I'm dealing with plain integers, so I don't think it's losing the NPC references at any point. During the game, firing a single bullet works fine; it travels across the screen and disappears as appropriate, and this can be repeated ad infinitum. However, when multiple bullets are on the screen at the same time and one is eliminated, some of the npcs representing the bullet stops, some move at double speed, and some behave as normal. If the references are getting shuffled during a 'destroy npc'. it makes sense that the references stored in the list would sometimes be pointing to non-existent npc copies, would sometimes have a few references pointing to the same copy (hence the speed up as the npc is moved two or more times in the game loop), and would sometimes behave normally.
It's certainly possible the list code is screwy somewhere, though I tested it pretty thoroughly. |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Thu Nov 13, 2008 3:23 pm Post subject: |
|
|
No reference shuffling happens.
an NPC reference should remain valid until the map gets reloaded.
The only thing I can think of that might be related to your problem is the fact that after you destroy an NPC, its reference number can be recycled by later create NPC commands.
Can you tell us more about your script? (or maybe even post it?) |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Nov 14, 2008 5:22 am Post subject: |
|
|
(Actually, npc references aren't shuffled in Custom either. It's the copy number that changes) _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Camdog
Joined: 08 Aug 2003 Posts: 606
|
Posted: Fri Nov 14, 2008 9:11 am Post subject: |
|
|
Sorry guys, I've once again posted my question prematurely. The issue was with my list code (a simple case of forgetting that calling the delete function with the default argument eliminates the last record in the list, not the current one. sigh) It just seemed that this explanation fit so well. I guess it was partially correct, since the super fast bullets were a by-product of reference re-use... anyway...
I do plan to post the code, soon. I hope to put together a pseudo-object oriented library for people to use. (In case you hadn't noticed yet, I'm talking about a hamsterspeak implementation of a linked list.) I just want to make sure I have some working proof of concepts in some example games first. Thanks for thinking about this! |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sat Nov 15, 2008 5:29 pm Post subject: |
|
|
Pseudo object orientated? I look forward to seeing it.
Have a look at this thread: Arrays vs. Linked Lists, where you'll find incredible amounts of discussion and scripts.
You might not want to hear this, but...
When arrays and dictionaries/associative arrays/maps are implemented (and for once, I think that this isn't too far off), I plan to add commands to wrap the use of these for common structures like queues and heaps. I am thinking about how a linked list should be implemented.
Perhaps I should optimise the internal implementation of arrays of length maybe <= 3 to make Lisp's list implement an efficient possibility. The thought makes me a bit queasy though.
I plan to implement associative arrays using a B+Tree (with a multimap variety), so that O(n) in-order traversal allows them to be used in creative ways. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Pepsi Ranger Reality TV Host

Joined: 05 Feb 2003 Posts: 493 Location: South Florida
|
Posted: Thu Feb 12, 2009 4:39 pm Post subject: |
|
|
I may be slightly off subject (and several months late) with Camdog's post, but I just wrote a script that confirms that NPC References and Destroy NPC commands do affect each other.
I assigned ten treasure boxes to the same NPC type, but used an NPC reference stored in ten different variables to separate each one.
The script calls a "destroy NPC" function after a treasure box is "pulled" (through animation and all the whatnot).
An autorun script is supposed to memorize through globals which boxes were pulled and which are still active.
This works like a charm except for one problem: The copy count shifts after the selected NPC is destroyed.
Case in point:
The first time out, I assigned individual references to variables.
Code: | set variable (crate1,npc reference (12,1))
set variable (crate2,npc reference (12,2))
etc. |
This is called three different times. Once in the activation, once in the pull (mid-animation), and once upon entering the map.
If certain conditions apply, some NPC references will be destroyed on the spot (to prevent opening chests that are already open). But this is done AFTER the references are reassigned. As in, before anything is destroyed, all ten instances exist.
However, what I noticed was that if I pulled the chest corresponding to "crate1" before pulling "crate2," then crate2 rendered itself inaccessible. If I pulled "crate10" after crate1, it still worked, but it would automatically return upon entry, whereas crate1 remained permanently pulled.
Suspicious of the copy count issue, I assigned a "show value" to crate1 and crate2's x,y coordinates before and after activation. It only called the "show value" on crate1's trigger. If I pulled crate1 first, the coordinates remained as they were intended. Crate1 reported (50,39) as its starting location and (50,39) after the destroy npc function is called (with a new coordinate check implemented). Crate2 reported (48,59) as
its starting location and its ending location. So far so good.
Then I restarted and tried it again by pulling crate2 first (which I couldn't pull if I started with crate1). Sure enough, pulling crate2 first rendered a different result. Not only did it pull, but crate1 was still triggerable.
So I triggered crate1.
The coordinates:
Crate1 = (50,39)
Crate2 = (84,21)!!!
Yep, the npc originally assigned to "crate3" was now subbing as crate2. Which explained why crate2 was inaccessible if I pulled crate1 first: Crate2 became crate1, which according to the script, was already pulled, and thus rendered inaccessible.
And it also explained why crate10 came back to life. According to a shifting NPC Reference, crate10 no longer existed, and what used to be crate10 became "crate9," which was never pulled.
The workaround for this was to use "npc at spot," but the whole point of my using npc reference was so I didn't have to hunt down the coordinates of every single treasure box littered in the maze.
But yeah, the shifting does exist, and it doesn't wait for you to leave the map. I think it will wait for the script to end at least. But once you destroy an npc and the script ends, the remaining npc references cycle downward, whether you stored them in a variable or not.
I doubt it's a bug, but it should be. It sure bugged me. _________________ Progress Report:
The Adventures of Powerstick Man: Extended Edition
Currently Updating: General sweep of the game world and dialogue boxes. Adding extended maps.
Tightfloss Maiden
Currently Updating: Chapter 2 |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Feb 13, 2009 5:32 am Post subject: |
|
|
Pepsi Ranger wrote: | This works like a charm except for one problem: The copy count shifts after the selected NPC is destroyed. |
Yes, of course. NPC references never change. But if you destroy the 4th NPC 1 then the 5th NPC 1 is the new 4th NPC. That's exactly how it's meant to work, and I thought logically.
Quote: | This is called three different times. Once in the activation, once in the pull (mid-animation), and once upon entering the map. |
What you want to do is store the NPC references once when you enter the map using NPC copy count numbers, and don't recreate them. Use global variables if you need to share them across multiplpe scripts.
Lesson learnt from all of this: perhaps we need some way to identify individual NPCs. Copy counts change, and there's no easy way to get the NPC reference of an NPC placed in Custom. We could make the NPC reference number visible, but I'm not sure if that's a good idea. I mentioned that NPC references stay static in Custom too, but there's no reason they will in future. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Fri Feb 13, 2009 8:07 am Post subject: |
|
|
How about if the NPC placement mode in the map editor allows you to assign a name to a specific already-placed NPC. That could be exported to your HSI file as a constant for the NPC's reference.
Although I'm not sure if it would be better to format the constantants as map 5 NPC: Dumpy the Mutt which is more specific...
or NPC: Dumpy the Mutt which is cleaner-looking and easier, but might be prone to confusion if accidentally used while you are on the wrong map :P |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Feb 13, 2009 8:50 pm Post subject: |
|
|
If you want to expose NPC references in HSI files, we also do it directly in Custom.
I vote for "Map XX NPC:Name", otherwise you can't give two NPCs on different maps a throwaway name like "left guard", which seems undesirable.
Perhaps it would also be a good idea to optionally encode the map number into an NPC reference for checking (maybe only in NPC references in HSI files, if the "NPC:Name" scheme is used), say new NPC ref = NPC ref + (1 + map) << 16. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Sun Feb 15, 2009 12:40 pm Post subject: |
|
|
Wait, where are you going to assign the names? The only issue here is with multiple copies of the same NPC ID, so you'd have to be able to name them from the NPC-placer. And where would you see them? There's not really room for a name in NPC-placing mode.
Honestly, all of this sounds like more trouble than it's worth to me. It might be helpful in a limited number of cases, but there will be other chances for confusion. If the author deletes an NPC in custom, he will need to re-export the hsi, and re-compile and re-import the script, in order to not screw everything up. This is at least as counter-intuitive to me as the current scheme. The author will also be in trouble if they accidentally put the NPC in the wrong place - deleting the NPC in question and re-placing it will also necessitate a lot of things outside of custom. I think the best thing to do would be to simply try to be as clear as possible about the constancy of references, but the dynamics of copy counts. _________________ 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 |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun Feb 15, 2009 9:52 pm Post subject: |
|
|
msw188 wrote: | Wait, where are you going to assign the names? The only issue here is with multiple copies of the same NPC ID, so you'd have to be able to name them from the NPC-placer. And where would you see them? There's not really room for a name in NPC-placing mode. |
On mouse over and/or with some toggleable viewing option.
Quote: | Honestly, all of this sounds like more trouble than it's worth to me. It might be helpful in a limited number of cases |
You may be right. It depends how much user friendliness would be improved.
Quote: | If the author deletes an NPC in custom, he will need to re-export the hsi, and re-compile and re-import the script, in order to not screw everything up. |
No they won't, NPC references are constant in Custom too.
But we could also have a command like get NPC reference("Dumpy the Mutt"). This is just so friendly, how could you refuse? :3
Quote: | The author will also be in trouble if they accidentally put the NPC in the wrong place - deleting the NPC in question and re-placing it will also necessitate a lot of things outside of custom. |
Hmm, good idea. We should be able to move NPCs around by clicking and dragging them with a mouse.
Quote: | I think the best thing to do would be to simply try to be as clear as possible about the constancy of references, but the dynamics of copy counts. |
Yes, it looks like it's not always understood so the documentation needs to be improved. But I think the NPCreference command documentation might not be the best place to explain all the details of NPC references, and so on. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Mon Feb 16, 2009 9:19 am Post subject: |
|
|
The Mad Cacti wrote: |
But we could also have a command like get NPC reference("Dumpy the Mutt"). This is just so friendly, how could you refuse? :3
|
I can't refuse! That sounds awesome. |
|
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
|