What is my error?

Blitz3D Forums/Blitz3D Beginners Area/What is my error?

ColeE(Posted 2016) [#1]
The following segment of code appears in my program:

DebugLog "i = " + i
DebugLog "botIndex% = " + botIndex%
DebugLog "validBotIndex% = " + validBotIndex%
If i=botIndex%+1 Then validBotIndex% = -1 Else validBotIndex% = i
DebugLog "i = " + i
DebugLog "botIndex% = " + botIndex%
DebugLog "validBotIndex% = " + validBotIndex%


My debug log produces the following:
i = 2
botIndex% = 0
validBotIndex% = 0
i = 2
botIndex% = 0
validBotIndex% = 2

What could possible be causing this? validBotIndex% should become -1, right?

Perhaps I'm doing something really stupid, but I've been looking and I cant find anything :/

Thanks for any help.


Guy Fawkes(Posted 2016) [#2]
First off, I know you're new so I'll let you know the rules. 1st, when posting a rather long set of code, use "[ codebox ]PUT THE CODE HERE IN PLACE OF THIS LONG SENTENCE [ /codebox ]". If it's only a few lines, use "[ code ] REPLACE SENTENCE HERE [ /code ]" instead.

Secondly, we need to see a reproduction of the full code and the error it's causing in order to solve this.

Hope this helps.

~GF


ColeE(Posted 2016) [#3]
I would consider that only a few lines, would you not? And I understand that the full code is often necessary, but in this case I don't see how any external cause could be affecting this. An If statement occurs between two blocks of DebugLogs, so that is the only thing that could be changing the values, no?


Guy Fawkes(Posted 2016) [#4]
If it's only a few lines, then use " [ code ] [ /code ]". Please follow the rules.

We need an actual demo reproducing the error in order to do anything.

~GF


Omnicode(Posted 2016) [#5]
i=2
botIndex%=0 ;<------- Problem

If i=botIndex%+1
    validBotIndex% = -1
Else 
    validBotIndex% = i
Endif


Let's first ask ourselves how could it be -1? If your i=2 then botIndex+1 MUST equal 2 to get -1 as an output.

Simple math outlines that 0+1 does NOT equal 2. So instead ELSE return i, i being 2.. you get a 2.

You might be tired and forgetting to assign a value to botIndex%.

For you to get -1 as an output with ANY given i then botIndex% must equal i-1.

Proof:
i-1+1=i
2-1+1=2

If you're having these sort've errors I recommend double checking the logic within your code.


ColeE(Posted 2016) [#6]
Yes thank you... I looked over that so many times and was sure it made sense, but it so obviously didn't... I guess I'm really tired today :) thanks.


Omnicode(Posted 2016) [#7]
No problem, good luck!