Pokemon-style berry plant things?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

User avatar
Taco Bot
Meat, Cheese, and Silicon
Posts: 484
Joined: Fri Jul 18, 2014 12:15 am
Location: Santa Cruz
Contact:

Post by Taco Bot »

Yeah, the global counts down just fine. Then it hits 0 and the plant never comes back.
Sent from my iPhone
User avatar
RMSephy
Metal Slime
Posts: 356
Joined: Mon Dec 21, 2009 5:56 pm

Post by RMSephy »

Are you removing the NPCs entirely when the tag is turned on? I think nextNPCReference() will only work for NPCs that are still on the map.
User avatar
Taco Bot
Meat, Cheese, and Silicon
Posts: 484
Joined: Fri Jul 18, 2014 12:15 am
Location: Santa Cruz
Contact:

Post by Taco Bot »

That looks like it just might be it. I've pinpointed the problem to the fact that it isn't resetting the tag. Maybe I should just make the npc invisible and change its interaction script? That seems hacky, but I guess it'd work.
Sent from my iPhone
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Oh, that makes sense. I double-checked and yes, "next NPC reference" only loops through currently visible NPCs.

But I know another way to do this. Try this:

Code: Select all

plotscript, berryRefillUpdate, begin
   variable(i, g)
   for (i, berryArrayStart, berryArrayEnd) do (
      g := readGlobal(i)
      if (g > 0) then (
         writeGlobal(i, g -- 1)
      )
   )
   variable(ref, arg, tag)
   for (ref, -300, -1) do (
      arg := readNpc(ref, NpcStat:scriptargument)
      if &#40;arg >= berryArrayStart && arg <= berryArrayEnd&#41; then &#40;
         g &#58;= readGlobal&#40;arg&#41;
         if &#40;g == 0&#41; then &#40;
            tag &#58;= abs&#40;readNpc&#40;ref, 9&#41;&#41;
            setTag&#40;tag, off&#41;
         &#41;
      &#41;
   &#41;
end
The negative ref numbers from -300 to -1 are the valid range of possible NPC numbers, and I know that unlike non-existent NPC ID numbers, nonexistant NPC ref numbers are safe and will not produce any error message (I know this because I do it a lot in my own games)

Let me know if this solves the problem.
User avatar
Taco Bot
Meat, Cheese, and Silicon
Posts: 484
Joined: Fri Jul 18, 2014 12:15 am
Location: Santa Cruz
Contact:

Post by Taco Bot »

I'm getting the same error as before...
Attachments
Erroerer
Erroerer
grapnes20000.bmp (63.55 KiB) Viewed 703 times
Sent from my iPhone
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Oops!

I said I used this method in my own scripts, but I should have looked more closely at my own scripts:

Try this:

Code: Select all

plotscript, berryRefillUpdate, begin
   variable&#40;i, g&#41;
   for &#40;i, berryArrayStart, berryArrayEnd&#41; do &#40;
      g &#58;= readGlobal&#40;i&#41;
      if &#40;g > 0&#41; then &#40;
         writeGlobal&#40;i, g -- 1&#41;
      &#41;
   &#41;
   variable&#40;ref, arg, tag&#41;
   for &#40;ref, -300, -1&#41; do&#40;
      if&#40;get NPC id&#40;ref&#41; >= 0&#41; then&#40;
         arg &#58;= readNpc&#40;ref, NpcStat&#58;scriptargument&#41;
         if &#40;arg >= berryArrayStart && arg <= berryArrayEnd&#41; then &#40;
            g &#58;= readGlobal&#40;arg&#41;
            if &#40;g == 0&#41; then &#40;
               tag &#58;= abs&#40;readNpc&#40;ref, 9&#41;&#41;
               setTag&#40;tag, off&#41;
            &#41;
         &#41;
      &#41;
   &#41;
end 
The part that checks if(get NPC id(ref) >= 0) makes sure that the NPC reference is valid before it uses it.
User avatar
Taco Bot
Meat, Cheese, and Silicon
Posts: 484
Joined: Fri Jul 18, 2014 12:15 am
Location: Santa Cruz
Contact:

Post by Taco Bot »

Mr. Paige, you are my hero. It's working flawlessly now! Thank you so much for your help with this.
Sent from my iPhone
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Happy to help! :)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Looks like an argument to "next npc reference" to not skip over disabled NPCs would be useful.
Post Reply