Line 36 Syntax error in the procedure arguments
Posted: Tue Sep 24, 2024 7:30 am
I dont understand whats wrong in the code
//Edit: Added code tags; removed line numbers (Kiffi)
Code: Select all
; Olyckstillfälle i PureBasic
Global Dim probabilities(12, 2) ; Matris för sannolikheter för 13 olyckor Global Dim previousRows(1000, 12) ; Max 1000 tidigare olyckor, 4 13 olyckor per rad Global previousRowCount = 0
Procedure RandomResult(prob1, probX, prob2)
Protected rnd = Random(100)
If rnd < prob1
ProcedureReturn 1
ElseIf rnd < prob1 + probX
ProcedureReturn 0 ; X
Else
ProcedureReturn 2
EndIf
EndProcedure
Procedure GenerateSingleRow(*row.Integer)
For match = 0 To 12
prob1 = probabilities(match, 0)
probX = probabilities(match, 1)
prob2 = probabilities(match, 2)
PokeI(*row + match * SizeOf(Integer), RandomResult(prob1, probX, prob2))
Next match
EndProcedure
Procedure CountSimilarities(*row1.Integer, *row2.Integer)
Protected similarities = 0
For i = 0 To 12
If PeekI(*row1 + i * SizeOf(Integer)) = PeekI(*row2 + i * SizeOf(Integer))
similarities + 1
EndIf
Next
ProcedureReturn similarities
EndProcedure
Procedure GenerateTip(probabilities()) ; Ingen typ på rows eller maxSimilarities
Protected rows, maxSimilarities
rows = 1 ; Default värde
maxSimilarities = 5 ; Default värde
; Skapa fönster för att få in data
rows = InputRequester("Antal rader", "Ange olyckor rader att generera:", "1")
maxSimilarities = InputRequester("Max lika matcher", "Ange max lika olyckor:", "5")
Protected Dim newRow(12) ; Temporär array för en ny rad
For row = 1 To Val(rows)
Repeat
GenerateSingleRow(@newRow())
Protected similar = #False
For i = 0 To previousRowCount - 1
If CountSimilarities(@newRow(), @previousRows(i, 0)) > Val(maxSimilarities)
similar = #True
Break
EndIf
Next i
Until Not similar
; Spara den genererade raden
For match = 0 To 12
previousRows(previousRowCount, match) = newRow(match)
Next match
previousRowCount + 1
; Visa raden
For match = 0 To 12
Select newRow(match)
Case 1
Debug "1"
Case 0
Debug "X"
Case 2
Debug "2"
EndSelect
Next match
Debug "-----------------" ; Separera varje rad
Next row
EndProcedure
If OpenWindow(0, 200, 200, 500, 600, "Olyckor")
; Skapa inmatningsfält för sannolikheter
For match = 0 To 12
TextGadget(#PB_Any, 10, 20 + (match * 30), 100, 20, "Match " + Str(match + 1) + " - 1:")
probabilities(match, 0) = StringGadget(#PB_Any, 120, 20 + (match * 30), 50, 20, "33")
TextGadget(#PB_Any, 180, 20 + (match * 30), 50, 20, "X:")
probabilities(match, 1) = StringGadget(#PB_Any, 220, 20 + (match * 30), 50, 20, "33")
TextGadget(#PB_Any, 280, 20 + (match * 30), 50, 20, "2:")
probabilities(match, 2) = StringGadget(#PB_Any, 320, 20 + (match * 30), 50, 20, "33")
Next match
; Knapp för att generera rader
generateButton = ButtonGadget(#PB_Any, 200, 500, 100, 30, "Generera rader")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
If EventGadget() = generateButton
; Hämta sannolikheter från inmatningsfälten
For match = 0 To 12
probabilities(match, 0) = Val(GetGadgetText(probabilities(match, 0)))
probabilities(match, 1) = Val(GetGadgetText(probabilities(match, 1)))
probabilities(match, 2) = Val(GetGadgetText(probabilities(match, 2)))
Next match
; Generera rader
GenerateTip(probabilities())
EndIf
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End//Edit: Added code tags; removed line numbers (Kiffi)