Author Topic: TMI Issue -- What's the Limit?  (Read 465 times)

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« on: June 07, 2014, 02:42:51 am »


               

I've been wrestling with an idea.  The core problem I'm trying to solve is the fact that if you have an item with charges, if as the charges drop down to the point where you can't use the item and then you boost the charges back up the item remains unusable.  If the item is 1 charge per use and has 3 charges, setting it to 4 charges makes it adjust to 4 uses.  But if it's 1 charge per use and has 0 charges, setting it to 1 charge keeps it as 0 uses.


 


The two main solutions I've seen suggested to fix this problem are the following:


 


1, remove and re-add the use property.  However, this would presumably clear the quickbar slot where the item was stored, which isn't acceptable.


 


EDIT: IT TURNS OUT THE ABOVE ACTUALLY WORKS.


 


2, have the player rest.  The catch is that this needs to work in-combat, which means ForceRest needs to be used AND the player has to be restored to the previous feats/spells/HP at a minimum.


 


As a result, I've written some code that loops through feats starting at value 0 and going up to 1115 (the last feat by default, player tool 10).  It checks the number of uses a feat has, stores this information as a local int, force rests, then decrements feat uses as appropriate.


 


The problem is that this produces a TMI loop.  However, the code is perfectly fine looping from 0 to 100.  And from 0 to 1000.  And from 1000 to 1150.  And from 900 to 1150.  But 0 to 1115 apparently breaks the instruction limit and gives me a TMI message.


 


This obviously has bad implications since I also need to do the same sorts of things for spells.


 


Presumably I could do something like separate this out into multiple scripts -- have one script check 0-600, another check for 600-1115 and rest, another decrement 0-600 if needed, and a fourth to decrement 600-1115 if needed.  But that obviously seems rather clunky and also has greater processor cost.  And I'd need the same sort of thing for spells.


 


Any suggestions regarding this?  Insight to offer on the TMI limit?



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #1 on: June 07, 2014, 03:53:26 am »


               

Few possibilities:


1) increase script efficiency via various scripting methods - this thread might help you


2) find another way to do that (for example try avoid loops in loops thats a biggest killer)


3) divide your script into multiple ones and execute them delayed (or multiple functions in one script etc.)


4) use NWNX plugin to increase the limit



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #2 on: June 07, 2014, 04:12:37 am »


               

Try making the Item use 2 charges per use and giving it an odd number of charges.



               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #3 on: June 07, 2014, 04:18:54 am »


               


Try making the Item use 2 charges per use and giving it an odd number of charges.




 


Didn't work when I tried it before looking at this solution.  As soon as the item registers that it has insufficient charges to use a property, you apparently need to rest or re-add that property to fix it.



               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #4 on: June 07, 2014, 04:42:42 am »


               


2) find another way to do that (for example try avoid loops in loops thats a biggest killer)


3) divide your script into multiple ones and execute them delayed (or multiple functions in one script etc.)


4) use NWNX plugin to increase the limit




 


2. I don't really see a way to avoid doing it.  Need to loop through every feat, need to then loop more in the first loop to increment/decrement, but the inner loop is skipped if the owner doesn't possess the feat.


 


3. Yeah, I mentioned that at the end of my post.  Are you saying multiple functions in one script will avoid the issue?  I thought it was for the script as a whole?  Could just put some of the loops in a new function in that case and problem solved.


 


4. Single player module, impossible.


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #5 on: June 07, 2014, 04:52:08 am »


               


2. I don't really see a way to avoid doing it.  Need to loop through every feat, need to then loop more in the first loop to increment/decrement, but the inner loop is skipped if the owner doesn't possess the feat.


 


3. Yeah, I mentioned that at the end of my post.  Are you saying multiple functions in one script will avoid the issue?  I thought it was for the script as a whole?  Could just put some of the loops in a new function in that case and problem solved.


 


4. Single player module, impossible.




2. yea no other way around it.


3. yes, just make void loop1() and void loop2(); and in main() call loop1 and delaycommand(0.1,loop2());


4. I see, but even when working on a multiplayer module I personally prefer choice 3 so I can test it without need to run server anyway


               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #6 on: June 07, 2014, 05:02:06 am »


               

3, ah, so the second loop would HAVE to be delayed?  calling loop1 and loop2 consecutively would still violate the TMI with no DelayCOmmand?  I know the DelayCommand effectively changes it into something else so maybe that's the reason.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #7 on: June 07, 2014, 05:04:35 am »


               


3, ah, so the second loop would HAVE to be delayed?  calling loop1 and loop2 consecutively would still violate the TMI with no DelayCOmmand?  I know the DelayCommand effectively changes it into something else so maybe that's the reason.




yes


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #8 on: June 07, 2014, 08:50:44 am »


               You can use AssignCommand instead of DelayCommand to by-pass the TMI check, with the advantage that it happens when the script finishes, rather than with some arbitrary delay.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #9 on: June 07, 2014, 12:41:15 pm »


               


Didn't work when I tried it before looking at this solution.  As soon as the item registers that it has insufficient charges to use a property, you apparently need to rest or re-add that property to fix it.




 


Correct.  Conventions that use 1 + m * n number of charges on items don't prevent either the need to refresh the item property when the uses run to zero, nor do they prevent item destruction, which is caused under the same circumstances when the item is not plot and there are not any later (in the sequential order listed on the item, which is newest to oldest) item properties with uses.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #10 on: June 07, 2014, 03:32:30 pm »


               

Is this for a custom item or all items with charges? If custom then you can give it unlimited uses per day and use your own code to track the charges. Changing the description to display the number of charges available is nice and easy enough to do as well. (Just be careful if you ever copy the item since the description changes won't be preserved.)


               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #11 on: June 07, 2014, 05:19:47 pm »


               

Giving the item unlimited uses per day means the user doesn't see the current available uses on the quickbar, so that's not an acceptable solution.


 


Amusingly enough this would be incredibly easy to do with a feat but it requires a hak (I've done a solution like that before for another project).



               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #12 on: June 07, 2014, 06:11:19 pm »


               


You can use AssignCommand instead of DelayCommand to by-pass the TMI check, with the advantage that it happens when the script finishes, rather than with some arbitrary delay.




 


Definitely like this more than DelayCommand in this case.


 


New problem!  I forgot ForceRest clears the action queue which is rather annoying in combat since you lose 6 seconds and disrupts your planned activities.


 


I might just have to do something like give it 5 charges at 1 charge a use and only allow it to do something when used at 3+ charges -- if used at 2 charges then it simply bumps itself back up to 2 from 1.  This would ensure the item never thinks it has 0 uses left -- but then it also misleads the player because they think they do, which is why I was trying to avoid this in the first place.


 


But the player having to remember the item only works at 3-5 uses would be better than disrupting their action queue in combat for no apparent reason, I think.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #13 on: June 07, 2014, 06:35:28 pm »


               

Wait, how you are increasing the charges? Usually this is done by some NPC or placeable, what is it that is doing it in middle of combat?



               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
TMI Issue -- What's the Limit?
« Reply #14 on: June 07, 2014, 07:01:41 pm »


               

A script.  Effectively you have an item that starts at 3 charges.  Once you use a charge, every 18 seconds a charge is restored until it registers it is at 3 charges again and then the script stops and waits until it gets used again.


 


The net result is that you can use the item every 3 rounds in general plus you can save up to 3 charges to release more rapidly if you're in a bad situation.  May bump it up to restoring a charge every 24 seconds depending on how testing goes, but that's just fiddling with tuning at that point.