Re: How to create a table of records?
Posted: Tue Jan 11, 2022 1:38 pm
Thank you jPV for your advices, I have a code in a little program that is works, here is, and I remove the item money.
Now I have the other doubt, how write the new record if your new score is higther than a score in the list and if it's true, now open the requester to write your name, if your score is low of the scores table, not write your name.
Thank you for your time and patience jPV, perhaps we will have a library of basic codes for cases as this, one Hall of Fame, Menus with visual effects, etc. as there are in CSS and javascript for example.
Code: Select all
Tabla Hall Of Fame.
Global hallfametable={
{name="Joe", points=100},
{name="Juan", points=80},
{name="Lucia", points=78},
{name="Ines", points=45},
{name="Rene", points=21},
{name="Megan", points=120},
{name="Megan", points=150},
{name="Rodrigo", points=6},
{name="Laura", points=5},
{name="Jack", points=4}
}
/**************************************************************************************************/
@DISPLAY {Title="Hall of Fame", Width=480, Height=350, Color=#BLACK, Borderless=False, NoClose=False,
KeepProportions=True, Sizeable=False, NoModeSwitch=True}
/**************************************************************************************************/
Function p_AddScore(name$, points)
; Insert the new score in the table:
InsertItem(hallfametable, {name=name$, points=points})
; Sort the table with a custom sort function:
Sort(hallfametable, p_SortFunc)
; If there are more than 10 entries, remove the last one:
If ListItems(hallfametable) > 10 Then RemoveItem(hallfametable, -1)
EndFunction
Function p_SortFunc(a, b)
If a.points = b.points
;Si los puntos son iguales que ordene por el nombre.
Return(a.name > b.name)
Else
;Ordena por defecto por puntuación más alta.
Return(a.points > b.points)
EndIf
EndFunction
Function p_ShowRecords()
Cls()
SetFont(#SANS, 28)
SetFontColor(#RED)
SetFontStyle(#ANTIALIAS)
SetFontStyle(#EDGE, #YELLOW, 1)
TextOut(100, 10, "NAME")
TextOut(300, 10, "SCORE")
;Lista de records.
Saltoy=40
SetFont(#SANS, 24)
SetFontColor(#YELLOW)
SetFontStyle(#ANTIALIAS)
;Print the table
For Local i = 0 To ListItems(hallfametable) - 1
TextOut(110, Saltoy, hallfametable[i].name)
TextOut(310, Saltoy, hallfametable[i].points)
Saltoy=Add(Saltoy, 30)
Next
EndFunction
Function p_EnterRecords()
Nombre$=StringRequest("Enter your name", "Enter your name", "", #ALL, 8)
If Nombre$=""
p_ShowRecords()
Else
Puntua=StringRequest("ENTER POINTS", "Enter the points", "", #NUMERICAL, 4)
If Puntua=""
Puntua=0
p_ShowRecords()
Else
;if is Ok, the new items has a new valor.
name$=Nombre$
points=ToNumber(Puntua)
p_AddScore(name$, points)
p_ShowRecords()
EndIf
EndIf
EndFunction
p_EnterRecords()
EscapeQuit(True)
Repeat
WaitEvent
Forever
Thank you for your time and patience jPV, perhaps we will have a library of basic codes for cases as this, one Hall of Fame, Menus with visual effects, etc. as there are in CSS and javascript for example.