playMaker

Author Topic: Compare Strings  (Read 3113 times)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Compare Strings
« on: July 09, 2016, 01:34:52 PM »
Hi!
I have a game time in my game. And I use two float variables for the time, because I have the format, 00:00:000. The first Float Variable, mm:ss, I use convert to seconds. The second Float Variable, I use Convert to String, and then I use build string, so I get these two Float Variables in one string, with the format I wrote above. My High Score list has 10 rows and is sorted by time. When the list is full, I need to beat the 10th place on the list to be able to write my name and get a high score.

I did this on my last game Memorita, but there the high score was sorted by score (Int) So I can easily use Int Compare, but in this case, I need to use String Compare. My question is: Is it a way to get Less than and greater than with a string variable? Or else I don't know how to solve it.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7624
    • jinxtergames
Re: Compare Strings
« Reply #1 on: July 09, 2016, 02:12:58 PM »
Hi,

There is not really a less than/greater than string compare
but you could use an array and then use array sort this will sort alphabetically
and numbers are sorted 0-9 so it would be possible

add you score string then sort, then use array contains and get the array index,
then you can use int compare on the array index.

if that does not work
try to convert you score at the 10th place into a float,

Get your minutes using "get string left" convert to a float and multiply by 60
then get your secconds with "get substring" and convert to float again and and it to your minutes result,
For millisecconds use "get substring" again or "get String Right" convert to float and divide by 1000 then add to your minute result,
then you can compare the 2 floats

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Compare Strings
« Reply #2 on: July 09, 2016, 08:17:25 PM »
Quote
Get your minutes using "get string left" convert to a float and multiply by 60
then get your secconds with "get substring" and convert to float again and and it to your minutes result,
For millisecconds use "get substring" again or "get String Right" convert to float and divide by 1000 then add to your minute result,
then you can compare the 2 floats

Hi!
I think this is what I need to do. I will experiment a bit in an empty scene, even if this sounds very difficult. Maybe I need to get back to you if I'm stuck. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Compare Strings
« Reply #3 on: July 10, 2016, 05:00:00 AM »
Hi, djaydino!

I got it to work!  :D

I have experimented a bit with the high score to add more columns.
So now I have the Players name, score and game time. Working very well! :)

Thank you for the help! :D
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7624
    • jinxtergames
Re: Compare Strings
« Reply #4 on: July 10, 2016, 12:55:26 PM »
Hi,
I am happy to help and that you got it working :)