Im trying to do a Bubble Sort function
Code: Select all
function sort takes integer dummy returns nothing
local integer array n[5]
local integer i
local integer temp
local integer runda
set i = 1
set runda = 0
set n[1]=GetRandomInt(2, 13)
set n[2]=GetRandomInt(2, 13)
set n[3]=GetRandomInt(2, 13)
set n[4]=GetRandomInt(2, 13)
set n[5]=GetRandomInt(2, 13)
loop
exitwhen runda == 19
if n[i] > n[i+1]
set temp = n[i]
set n[i] = n[i+1]
endif
set runda = runda + 1
if i == 4
set i=1
endif
call DisplayTextToForce( GetPlayersAll(), n[1] )
call DisplayTextToForce( GetPlayersAll(), n[2] )
call DisplayTextToForce( GetPlayersAll(), n[3] )
call DisplayTextToForce( GetPlayersAll(), n[4] )
call DisplayTextToForce( GetPlayersAll(), n[5] )
endloop
endfunction
I tried to make it in GUI now but that didnt work either the code
Code: Select all
Random
Events
Player - Player 1 (Red) types a chat message containing -random as An exact match
Conditions
Actions
For each (Integer A) from 1 to 5, do (Actions)
Loop - Actions
Set SortArray[i] = (Random integer number between 2 and 13)
Set i = (i + 1)
Game - Display to (All players) the text: (String(SortArray[1]))
Game - Display to (All players) the text: (String(SortArray[2]))
Game - Display to (All players) the text: (String(SortArray[3]))
Game - Display to (All players) the text: (String(SortArray[4]))
Game - Display to (All players) the text: (String(SortArray[5]))
Code: Select all
Test Bubble Sort
Events
Player - Player 1 (Red) types a chat message containing -sort as An exact match
Conditions
Actions
Set i = 1
Set Runda = 0
For each (Integer B) from 0 to 19, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
SortArray[i] Greater than SortArray[(i + 1)]
Then - Actions
Set temp = SortArray[i]
Set SortArray[i] = SortArray[(i + 1)]
Set SortArray[(i + 1)] = temp
Else - Actions
Do nothing
If (i Equal to 4) then do (Set i = 1) else do (Do nothing)
Set Runda = (Runda + 1)
Game - Display to (All players) the text: (String(SortArray[1]))
Game - Display to (All players) the text: (String(SortArray[2]))
Game - Display to (All players) the text: (String(SortArray[3]))
Game - Display to (All players) the text: (String(SortArray[4]))
Game - Display to (All players) the text: (String(SortArray[5]))
edit: i Saw in call DisplayTextToForce( GetPlayersAll(), n[5] ) i didnt use integer to string...... But that thing wouldnt make all the errors i got before anyways.