Page 2 of 2

Re: Highscore and complex animation problem, please help!

PostPosted: Fri Mar 15, 2013 6:55 pm
by m93c
I wrote a code in wich I tell the game to create save and insertname actors only if the score is higher than the 10th score.
I put in save actor some conditions to determine in wich position place the name.
For example if you obtain the highscore:
If( score.textNumber>firstscore.textNumber)
strcpy(name[3], name[2]);
strcpy(name[2], name[1]);
strcpy(name[1], name[0]);
sprintf(insertname.text, name[0]);
saveVars("Highscore.dat", "nscore");

The conditions are the same I used for score and they work pretty well.

The sprintf part changes according to the score obtained.
For ex if you obtain a score higher than the 2nd the code is:
If(score.textNumber<firstscore.textNumber)
If(score.textNumber>secondscore.textNumber)
strcpy(name[4], name[3]);
strcpy(name[3], name[2]);
strcpy(name[2], name[1]);
sprintf(insertname.text, name[1]);
saveVars("Highscore.dat", "nscore");

Name[0] (the name in the first place) doesn't change and so on until the 10th place.
I know it is a very long way to do this but it is very effective, at least for score...

Strcpy( variable1, variable2 to be copied in 1) right?

Re: Highscore and complex animation problem, please help!

PostPosted: Sat Mar 23, 2013 12:23 am
by bamby1983
Your logic seems sound. You can reduce the number of lines of code by using for loops. I would suggest something on the following lines:

1) Assuming your array is sorted, use the for loop to compare the new score with each of the existing high scores in descending order. Store the array index of the first high score that is less than the one just achieved in a temporary variable (which will have to be initialized to a value of -1 at the start of the function/code). If the value is less than all the stored values, then it remains at -1
2) Use an if-statement to check the value of the temporary variable. If it equals -1, don't proceed with the next steps. It means that the achieved score doesn't qualify to be amongst the high scores
3) Then use another for loop to copy the value of an array variable to the next higher index. For example, the value of index n would be copied to index n+1. This should start at the index that corresponds to the value stored in the temporary variable in step 1. Also ensure that you do not try to copy the value of the last element in the array to the next higher index or you will get an array out of bounds exception error. Use an if-condition to check whether the array index is equal to the max index and only proceed if it isn't. If you're using an increment operator, you should use "break;" to exit the loop if you each the last array index
4) Now add the score just achieved by the player to the array index stored in the temporary variable in step 1
5) Repeat steps 2 and 3 for the player names

Re: Highscore and complex animation problem, please help!

PostPosted: Sun Mar 24, 2013 7:23 pm
by m93c
Thanks, I'll try :D

Re: Highscore and complex animation problem, please help!

PostPosted: Thu Mar 28, 2013 11:43 am
by m93c
ok I solved all my problems! :D :D :D
just uncecked create at startup for text Actors and let create them by another one.

Just one last thing, how can I limitate the number of characters inserted in the inserttext actor to 3?

Re: Highscore and complex animation problem, please help!

PostPosted: Thu Mar 28, 2013 1:13 pm
by bamby1983
m93c wrote:how can I limitate the number of characters inserted in the inserttext actor to 3?


I'm not sure, but perhaps you can store the text in a variable that is a character array of size 3 ( for example - char name[3]) so that it only takes three characters. I'm not sure if it will work or return an error if the user enters more letters, though.

Re: Highscore and complex animation problem, please help!

PostPosted: Fri Mar 29, 2013 10:46 am
by m93c
Error:
cannot convert from char to ARY[256]char...

I'll make a littler input window :mrgreen:
Thank you for your help but if you have other ideas to do this I'm here :D

Re: Highscore and complex animation problem, please help!

PostPosted: Fri Mar 29, 2013 11:38 am
by bamby1983
m93c wrote:Error:
cannot convert from char to ARY[256]char...

I'll make a littler input window :mrgreen:
Thank you for your help but if you have other ideas to do this I'm here :D


A smaller input window will not help as users can still enter larger names (the txt will keep scrolling).

What data type are you using to store the user's input? It should ideally be char [3] (a character array of size 3), not char (which is an ordinary, single character variable).

Re: Highscore and complex animation problem, please help!

PostPosted: Sat Mar 30, 2013 9:41 am
by m93c
I know the text will scroll, but if you see a little window, when it's full you stop writing :mrgreen:

However I use a string variable for each name (name1, name2, name3...) because if I use a string with array, ex. name[10], it can store only 11 characters and, don't know why, it saves only one name. Maybe if I make arrays of 3 my 10 variables it should work...
What do you think?

Re: Highscore and complex animation problem, please help!

PostPosted: Sat Mar 30, 2013 2:53 pm
by bamby1983
I think you should make each name a separate character array with 3 variables.

Re: Highscore and complex animation problem, please help!

PostPosted: Mon Apr 01, 2013 4:21 pm
by m93c
Maybe the only solution...
If it doesn't work I only hope that future players' names won't be Elizabeth, Alexander or longer :lol: :lol: :lol:
Thank you all for your help!

Re: Highscore and complex animation problem, please help!

PostPosted: Mon Apr 01, 2013 5:56 pm
by skydereign
bamby1983 wrote:I think you should make each name a separate character array with 3 variables.

Not really. You could use a char array, and chop it to the right length, in this case set the fourth character to null. Or use your own character insertion, that way you can prevent key input if the length is 3 or greater.