Giving lines in list object seperate values?
Hello! I am creating a game where you add names of the players with an edit box and a list object, so when you click a button, the list gets the name in the edit box.
But I want to have it so that each player can have a score. This wouldn't be a problem if the number of players was static, but it is dynamic (meaning you can add and remove as many players as you want).
How do I attach a seperate score to each name on the list, and sort it so that for instance the leading player (with highest score) is on top of the list? Also, I need to be able to trigger events for players with highest/lowest score.
Thank you in advance for your replies :)
Re: Giving lines in list object seperate values?
Yikes, you need to sort numerically, something list object is not capable of usually...
It's too complicated to explain here in text, so I'll make an example.
Re: Giving lines in list object seperate values?
I am looking into arrays now, but any example would be very kind :)
Re: Giving lines in list object seperate values?
Scratch that about being complicated. Just set a list object "Sort" property on in the first tab of the object properties.
To insert a score, use:
List: Add line Left$("[color:#33DD33]0000000000[/color]", [color:#33DD33]10[/color]-Len(Str$([color:#FF0000]My score here[/color])))+Str$([color:#FF0000]My score here[/color])+"|"+[color:#3333FF]My name here[/color]
[color:#33DD33]10[/color] is the length of the "[color:#33DD33]000000000[/color]". Adjust both string and length to taste.
After all scores are added, use:
List Line$("List",1) to get the lowest scored line;
List Line$("List", List Nb Lines("List")) to get the highest scored line;
Left$(Line, Find(Line,"|", 0)) to get the score on a line;
Right$(Line, Len(Line)-1-Find(Line, "|", 0)) to get the name on a line.
Yay for Darkwire optimized code...
Re: Giving lines in list object seperate values?
Okay, I get some of it, but why do you have "insert score here" twice on where you add a line?
When I test the game, it only shows the last of the "insert score here" you adviced me to put in.
For example if I put the number 2 on the one that says
'Len(Str$(My score here))' and 1 on the second one, I only see "00000001 | Bob". What's the first line 'Len(Str$(My score here))' for?
Also, does this have something to do with the sorting of the list? Because it seems that the list moves the highest score up the first time, but if a new higher score gets added to the list after that, it doesn't go on top. It goes at the bottom or in the middle of the list.
Re: Giving lines in list object seperate values?
Len() gets the length of text, therefor the actual text doesn't matter, just the length. Obviously, though, you'd want to use the score that the player managed to get.
And the behavior is intended to be like that, the highest score will always be at the bottom, not the top. This is because you'd want to hide that list object and not let the player see it, and you'd use the other onformation SortaCore gave you to get scores and names to display however you want.
Re: Giving lines in list object seperate values?
I see. Thanks! I figured out that the reason the scores ended up the wrong places, was that it gets sorted alphabetically from the names, and not by the score.
But when I am using this expression to get the score from a line..:
Left$(Line, Find(Line,"|", 0))
..I get a message saying it's wrong. I think it is "line" that is the problem.
My expression is more like
Left$(Line, Find(Line,"|", value( "Active player" )))
The active player thing is a counter that says which player on the list things happen to (it is random).
Basically, what I want with this sentance, is to get the score from the line that has the random active player.
Any tips? I think my brain is starting to fry, as I could be more experienced with expressions in MMF2 :P
Re: Giving lines in list object seperate values?
My score here is twice, the first time is to get the number of 0s to put on the front of the line, the second time is the one the user can see.
In the example, I have a maximum of 9 zeros appended, for example if the score is 1, it'll put 0000000001|Username, which the List object will sort correctly. Otherwise, you'll get
1023|Highscore
53|Lowscore
because 5 is higher alphabetically than 1.
so the 0s move it to
0053|Lowscore
1023|Highscore
which is what you want :)
Re: Giving lines in list object seperate values?
Yikes, this code all good for you?
Re: Giving lines in list object seperate values?
I thiiink I understand maybe.. Here is a long post :P
Left$("000000000", 9-Len(Str$(4)))+Str$(50)+" | "+Edittext$("Namefield" )
Means the numbers get sorted in 4s so that 1000 is higher than 256 etc? If I had 0 or 1 there, 256 would be sorted before 1000.. Or am I wrong? And the Str$(50) means the player basically gets 50 points, that is also shown on the list?
But I don't get how you can update that then. If the player gets 50 more points. Do I have to delete the previous line and add a new one that is relative to the old one? Then I need a temp score so that it stores "50", deletes the line, and adds i.e. 50 to the previous 50. And to make a temp line somewhere else, I need to get the score that is on the list from before.
I use
Left$(Line, Find(Line,"|", 0))
for that? And this sentance does not work for me, because it is apparently a "wrong expression" to MMF2. The 0 in the end there, I guess is the line number to get the score from? Which is then the line of the active player that is getting the score.
Re: Giving lines in list object seperate values?
Yikes, you've lost it! Come onto Gwerdy chat, link is on the right.
Re: Giving lines in list object seperate values?
Yikes! Yikes, just check this MFA:
http://mfa.aquadasoft.com/view/1309017817-HighScores
Re: Giving lines in list object seperate values?
Thank you LB! Just what I needed. Much appreciated, guys :)
I have forgotten everything about MMF, because I stopped using it for a couple of years.. and also I haven't made many advanced things for it yet :)