Logic error
Hi, I want to do next page switch. With input E it works and when I want to go backwards and press Q in list and I'm going from index 1 to 0 it will give an error that says I have wrong index but I'm on 0 index in list.
14 Replies
And I have forgotten to mention that I changed the if (currentPage <= 0) to currentPage == 0
Well, that would be the issue
You're at index 0
Then you decrement it
It's now
-1
-1
is not equal to 0
What on earth is
skok
?it is boolean. When code detect that next index will be more or less it will be true so nextpage will be the opposite index
I'm maybe dumb but how to fix it?
Go back to using
<=
Yeah but it still gives me the error
The same one?
Yes
Could be because you never change
currentPage
You roll nextPage
over, but currentPage
stays as that -1
So next time you use it... it's -1
I don't think so. I added currentPage = 4; when skok is true. There is some other problem, because when I'm going from index 1 to 0 it still kick me off
Do you want video to show you the problem?
No need, I know what the problem is
I guess you should just debug it
It works but for some reason it won't change to page 4
I somehow fixed it but this is smaller problem
Thanks
$debug
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.