Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / AI Issue with timers

Author
Message
TheViking
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 31st Jan 2015 03:22 Edited at: 31st Jan 2015 03:50
Hey all.

I'm working on the AI system (very basic so far) for a turn based style. So far I have it so that as a character/enemies ability activates it adds them to a queue where runs through each character one at a time and reorders them after the attack is done. So far, it seems to work fine, for the most part, until the fourth or fifth player is added to the list (there are currently only 3 or 4 players in the battle.

This is where my issue is. When the attack initiates, the attack timer begins. When it reaches a certain value (10000), the attack plays through and damage assigned (soon) and the list moves up. However, on the fourth or fifth list person, the attack timer continues to loop but never finishes the attack and reorders the list. I'm assuming that there is some variable issue or array issue at play here, but just seeing if anyone can pick out the flaw, because I'm getting a bit stumped since it works for a number of players, and will even run through that player a second time before it stops.

Here's the code:




The triggering code is:


Thanks for any suggestions,

If you need any further explanation of the arrays, let me know.

OK, since I'm sure you'll be asking what the heck these arrays mean... I'll quickly explain. Stats(x) is the hero stats, enemy(x) is self explanatory. Sequence is the order to which they get placed in the queue. AP is the action points allowed to do an attack. And, BattleOrder(x) is the queue that holds all the info (in the end). Hope that helps a bit.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2015 13:38
What is "x" in this line of the function Reorder()?



Is it a global or what? The same variable appears in the other functions but isn't given a value anywhere unless I missed something.



Powered by Free Banners
TheViking
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 1st Feb 2015 16:54 Edited at: 1st Feb 2015 16:56
Hey GG, x is a global that increases each time a player is added to the queue. It increases the array so that it doesn't overwrite the previous.

In this case x = x-1 decreases the x value so that when setting up the order of the queue, it doesn't skip one spot. I had to add it in because without it, the order would fill the first three spots, then would have a blank spot then fill the fifth spot. This ensures that it subtracts one and then fills the right position.

I hope that makes sense, lol...

EDIT:
This is where the x value is increased to fill the BattleOrder Array. x, is only used for filling this array.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2015 17:21
Could you supply a simple example of the possible values that Stats(n).Sequence and x could take when that loop is entered? At the moment I can't see what the loop is supposed to be doing.



Powered by Free Banners
TheViking
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 1st Feb 2015 18:58
Lol, sure!


Sorry, it may seem lengthy.

So...



Hope this is what you were asking for... if I misunderstood, I will try to be a little more clear.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2015 21:19
Quote: "if I misunderstood, I will try to be a little more clear"


Yes please. I merely wanted typical values so I could check that the loop does what it's supposed to do, i.e. which particular input values for that loop give the wrong output values - and what are those values? Perhaps you've done that already but, according to you, it doesn't work so one of the numbers is wrong. Have you checked which one? That would be the first thing I would do rather than ask someone else to try and understand the whole logic of your code.

As a general rule it helps when bug-hunting to identify where the logic first goes wrong, i.e. identify which inputs give a result different from what you expect. We should then be able narrow it down ourselves. That doesn't always work of course, usually because we've made an incorrect assumption about what a particular piece of code does. But the first step is to identify particular values which give a wrong result. Then we can all make progress.



Powered by Free Banners
TheViking
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 2nd Feb 2015 01:32
Ah, that's what you meant. Yes, I have both the timers, sequence, Character info and about 30 other variables displayed on screen at all times to constantly check to see if anything seems out of place.

Currently, as I watch them, I honestly see no issue at all. Once the AttackTimer reaches 10000 it cycles back to 0, which it's suppose to do. However, the Reorder() function does not trigger, yet all the variables needed for it to trigger are met, according to the on screen text printouts.

So, as I'm running the fight script. The battleorder filled up 4 times with 2 different character (player 2, enemy 1, player 2, enemy 1) and on the second player 2, it reaches the reorder function and doesn't reorder.

Now, I thought maybe because it's triggering the same player a second time as to why, but then tried it out with 3 players.

So, Player 2, enemy 1, and enemy 2. In this case the same held true. Player 2 went, then enemy 1, then when it reached enemy 2, it continues to loop the attack timer without triggering the reorder() function. No one changes positions. The stats(x).Sequence for all players remains the same, and the enemy(n).Sequence remains the same. Battleorder(n).Sequence also remains the same. No change.

So, I have watched the variables as it was originally my first guess, and they all seem to line up fine. I'm sorry if it seemed like I posted without trying myself. But, I have looked and looked and can't seem to find it. I don't like to ask for help, as a matter of fact I despise it.

But, I understand your point of view, and I guess I jumped to the forums too quickly in some peoples eyes.
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 2nd Feb 2015 04:42
For issues like this, dumping variable values to a logfile on disk might be better than printing them to the screen. It's easy to miss things.

At a glance sometimes your .AttackTimer is using = and sometimes using > for testing values. Perhaps the = is too specific and it skips over 9000 and 10000 ? Just an inconsistency I noticed.

TheViking
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 2nd Feb 2015 05:05 Edited at: 2nd Feb 2015 06:07
I tried switching them to all >, and no change. Thanks for the suggestion though. As far as I can tell, it seems to ONLY occur when it goes BACK to a character that has already attacked once before. So, once it does a full cycle of all the players.

EDIT:

Ok, I noticed this before as well, but when I shorten the AttackTimer from 10000 to 5000, it won't trigger anymore as well. Yet, all the values required to do so are met (at least seeming).

Sorry, I don't exactly know how to dump to a logfile. Never got that far before to look into it. But, will probably start at some point soon.

EDIT EDIT:

Ok, actually, some work with the > signs seemed to help. Now, it goes a few sequences further when only fighting one enemy, but still loops like before after a while, and no longer works. Sorry all, just frustrating.

SOLVED!!!!:

Thanks guys!
tiresius, thanks to you mentioning the > sign I clued into something that I didn't before. The APCurrent Value for the characters can go up higher than 2!! and therefore, since they keep accumulating and not getting used up as quickly as they came, it went up to 3 making the Stats(n).APCurrent = 2 not true!!!!

I can't believe I didn't see that. Sorry if I wasted your guys time, but it was appreciated, and if not for you I probably wouldn't have noticed it for a while.
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 2nd Feb 2015 06:13 Edited at: 2nd Feb 2015 06:14
Logfiles are good because many processes run too fast to track by eye. This way you can run the game, see the event happen, read the logfile, tweak code or add more logging, rinse and repeat.

If you don't have it yet, get Matrix1Utilities which has a nice append to file command and a ton of other goodies for DBPro.

Here are the functions I have used.


And in code do something like this (example dumping variable 'floorType' )
debugOutput("Illegal floorType done: " + str$(floorType))

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Feb 2015 13:24
Quote: "I can't believe I didn't see that. Sorry if I wasted your guys time, but it was appreciated, and if not for you I probably wouldn't have noticed it for a while."


No problem. These things happen to all of us - sometimes all we need is a nudge to get us to look at our code more carefully. Glad you got it sorted and thanks for letting us know.



Powered by Free Banners

Login to post a reply

Server time is: 2026-07-05 12:51:34
Your offset time is: 2026-07-05 12:51:34