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 / Crazy bugs, getting mad (comparing string to array string)

Author
Message
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 18:27 Edited at: 4th Apr 2016 18:31
I am trying to check if in my 32 players multiplayer game the same account log twice, for some misterious reasons I am failing to do such a simple thing, both client side checks and server side checks.

CLIENT SIDE

I am trying to compare the username of the player to every player logged in the server, before to chose the slot to take, both lowered, here's the code.



So here the problem is, randomly it fails to compare the username to the other players, even if the name is EXACTLY the same (both strings are lowered).
As you can see from my code I am also doing some logging to understand what is going on, and this is the result printed on the file:



How can it be playertest different from playertest ???
The weird thing is that if I try to do a separated small test it seems to work, but there is no reason to make a difference as I print out on file all the maths and no way that playertest could be different than playertest!


SERVER SIDE

This is the serverside part (only the part related to the slot assignement) that check if the player is already logged (same as client, lowers both strings to compare them)




I have fixed and found workarounds for things much complex than this and now I fall for a simple string comparison, what am I doing wrong?
Just one of these 2 checks should be enough "client or server" but I can't manage to work none of them.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Apr 2016 19:16
My guess is that one of the copies has unprintable characters. Have you checked the length of each string? Does one of the strings contain a space or some other special character? If that example consistently gives that result then you should be able to hunt the problem down.


Powered by Free Banners
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 19:48
As you can see from the list printed there is no spaces at all, the playername is inserted by hand from me using this function:

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Apr 2016 21:01
That doesn't tell me anything. Have you checked the two strings, byte by byte, when the program thinks they differ? If you haven't then you should. Ditto string length. Do the checks. When a program gives a wrong answer, never assume that your code is working as you expect. Find out what it is actually doing, not what you think it's doing.


Powered by Free Banners
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 21:31
I will try to make some tests, by the way I suspect that the problem is when username is created, so when the function I have posted above is called.
I say this because after the login, if the string comparison is correct, it keeps to be right even connecting and disconnecting from the server, if after the login the comparison doesn't work, it won't work even disconnecting and reconnecting (or better accessing the slot request page that is where I do the check).
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 21:49 Edited at: 4th Apr 2016 21:51
You probably nailed the point, this is the result of the test:



Now, why this happens? playertest has 10 chars, where is the last char not displayed?
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 22:14
This runnable code demostrate that the problem is actually the function mentioned above, try several times to type "playertest", it will show 11 characters while the lenght should be 10.


Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 22:18
After a few tests I have "maybe" fixed the problem, if you add Username$= TRIM$(Username$) it will be trimmed to the 10 characters that should be, I will test this now on my game.
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 22:35
Seems to work in the game too, damn, these bugs scare the crap out of me.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 4th Apr 2016 23:16
Yeah, trim is always a good practice when comparing strings taken from some form of input, the same as using lower (as long as you don't care about casing)
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Apr 2016 23:24
The bad thing is, Printing the variable, you actually do not see the last char added to the variable, not even as space, if you do Username$ + "sometext" you don't see "playertest sometext" but still "playernamesometext", and this makes way harded to detect which is the problem.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Apr 2016 23:58
Quote: "You probably nailed the point, this is the result of the test:"


Thanks for the feedback. Sounds like you are on track for a solution now. I always find working with strings awkward for just this kind of reason.


Powered by Free Banners
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 5th Apr 2016 00:02
My guess is when the user his enter to submit the name, it adds \r\n or the like
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 5th Apr 2016 00:09
Yeah I was thinking that too in fact I have tried to remove from the string "\n" and "\r" but without any success, so I have tried with the trim function later.
When I started to implement the connection part with the server I was having problems with the data and removing "\r" fixed the problem.

Login to post a reply

Server time is: 2024-03-28 23:47:50
Your offset time is: 2024-03-28 23:47:50