![]() |
-now what am i doing wrong?
ive been nored and working on a rescript of the inventory system and its comin along pretty good
the script works fine except for ONE thing! it repeats the "replace string" -for adding to the quantity of the item- twice for seom hideously odd reason. if (actionact) { if (lindexof(#s(this.item),client.inv)==-1){ addstring client.inv,Apple; addstring client.invcount,1; } else { replacestring client.invcount,lindexof(#s(this.item),client.inv) ,#v(strtofloat(#I(client.invcount,lindexof(#s(this .item),client.inv)))+1); } } the action command is simply if (keypressed){ if (keydown(6)){ triggeraction playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playe rdir)*2,act,; } } any help, id appreciate ^_^ |
either keypressed is running twice or that part of the script isn't the problem, do you have a timeout running around the execution of this script? (within the same script I mean)
|
No timeouts at all.... i ran debugger on the actionact part and it executes twice.. i havent debugged on keypressed yet
Any ideas on how ta fix it? |
does this happen for others aswell?
I'd say restart the npc server, but that may not be needed, or be the problem... ooh! do it anyway! |
hmmm...
If you press the key 'a' then it sends the triggeraction. As long as the key is down it will continue to send the triggeraction.
I assume the part sending the triggeraction is a weapon and the other is an object. Wouldn't you have to destroy the object after the player gets it so the player will not get it added again? |
Re: hmmm...
Quote:
what if there's twelve of the items in that pile and you only want to pick up 3 of them? |
Re: -now what am i doing wrong?
Quote:
I think the problem is that you use keypressed and keydown. You should either figure out the key that was pressed by the #p thingies you get along with keypressed, or you should use a timeout loop and check whether the key was already pressed in the previous frame (by doing this.oldkeydown = keydown(6) after everything). Otherwise, any keypress while A is pressed will trigger the action again. It is not true, though, that this gets looped as someone said. Other than that, you should do some precalculating instead of writing everything in the replacestring line. It helps not only readability but also might be more efficient, if it takes less time to access variables than it takes to call lindexof and stuff. But readability still wins. NPC Code: Next, you might consider allowing items to not only have a type but also a quantity so if many items of the same type are close, they get put together into one NPC. And have a look at my item system, perhaps. |
no idea why it was repeating the keydown command but i DID end up fixing it by making a quick pause in the (actionact) part
NPC Code: im all curious about the repeatingness now... X_x a bug? |
Quote:
i was intrested how you had NPC Code: i was unaware that was possibile, and perhaps thats the reason it is repeating, because you had keydown, which reads fast i thought, so when the key is pressed and its reading it, seems like twice before you can get your finger up. No bug i dont think. |
... Actually none of them repeat, unless you hold them down too long, make sure your keyboard settings don't repeat keys too fast. If not that, it's lag, use a timeout and check that the key wasn't down last time it was checked.
weapon; NPC Code: toAndy: keydown is a flag, it can't "read fast" |
Quote:
NPC Code: that perhaps that same thing was applying itsself here. |
Quote:
|
Quote:
|
I never liked keypressed ;)
|
Quote:
' hehe i like keydown2 |
Quote:
|
Your better off using the timeout approach anyway, it seems to be more reliable
-psuedocode- NPC Code: why did I even bother making that pseudocode anyway? |
It is not really pseudocode. :p
NPC Code:on a timeout, |
Quote:
|
| All times are GMT +2. The time now is 11:40 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.