Jass help

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

Gwypaas
Junior Member
Posts: 36
Joined: May 13th, 2007, 5:56 pm

Jass help

Post by Gwypaas »

wtf is wrong with this function????

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 really need help bc this is the thing the map im working on is built on.

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.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Jass help

Post by Aero »

Tell me exactly what you want this function to do
Gwypaas
Junior Member
Posts: 36
Joined: May 13th, 2007, 5:56 pm

Re: Jass help

Post by Gwypaas »

it Gets a integer array n with 5 spaces then i want to sort them up like 1,2,3,4,5 so it changes place on all until they are in right order.
I tried to use Bubble Sort to sort them :P
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Jass help

Post by weirdone2 »

So let me get this rite you want to display the data to player from least to greatest?

And as for your coding, i'll add what I notice.

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]  (Will always be if n[1]>n[2])
         set temp = n[i]  (Will always set temp = n[1])   {This basically is just setting temp to n[1] and n[1] to n[2] if n[1] is 
         set n[i] = n[i+1]                                               greater.}
      endif
     
      set runda = runda + 1
         
      if i == 4 (i will never = 4)
         set i=1
      endif
      call DisplayTextToForce( GetPlayersAll(), n[1] ) {These will show n[1-5] but remeber you just set n[1] to n[2]}
      call DisplayTextToForce( GetPlayersAll(), n[2] ) (are you using n[3-5] for anything? or did you jsut forget to set i=i+1)
      call DisplayTextToForce( GetPlayersAll(), n[3] )
      call DisplayTextToForce( GetPlayersAll(), n[4] ) 
      call DisplayTextToForce( GetPlayersAll(), n[5] )
   endloop
   
endfunction


A code that should work for ordering numbers in order.

Code: Select all

local integer array n[5]
local integer array nn[5]
local integer i=1
local integer l=1
local integer L=1
local integer K=1

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
 loop
  loop
 exitwhen K=5
  exitwhen L=5
   exitwhen i=5
   if n[i] >= nn[K] then
    set nn[K]=n[i]
   endif
   set i=i+1
  endloop
  if n[l]=nn[K] then
   set n[l] = -1
  endif
  set l=l+1
  set L=L+1
 endloop
 set l=1
 set L=1
 set K=K+1
endloop
if nn[5]>0 then
call DisplayTextToForce( GetPlayersAll(), nn[5] )
if nn[4]>0 then
call DisplayTextToForce( GetPlayersAll(), nn[4] )
if nn[3]>0 then
call DisplayTextToForce( GetPlayersAll(), nn[3] )
if nn[2]>0 then
call DisplayTextToForce( GetPlayersAll(), nn[2] )
if nn[1]>0 then
call DisplayTextToForce( GetPlayersAll(), nn[1] )


Well this should work didn't bother to test it though so if it doesn't just let me know and i'll see about debugging it. Also this does not display duplicate numbers.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Jass help

Post by Aero »

This will sort and display 5 random integers from 2-13 by order of Greatest to Least.

Code: Select all

function sort takes nothing returns nothing
local integer array n
local integer array a
local integer b=1
local integer c=1
local integer d=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 c>5                                                   
loop
exitwhen b>5                                       
if n[b]>d then           
set d=n[b]               
set a[c]=d             
set a[0]=b
endif
set b=b+1
endloop
set d=a[0]
set n[d]=0
set d=0
set b=1
call DisplayTextToPlayer(GetLocalPlayer(),0,0,I2S(a[c]))
set c=c+1
endloop
endfunction


If this isn't what you want tell me
Gwypaas
Junior Member
Posts: 36
Joined: May 13th, 2007, 5:56 pm

Re: Jass help

Post by Gwypaas »

no i want 5 random integers to på ordered up... Using the bubble sort. I already got the random integers but now i need them to be ordered up like this
21895 should be 12589 thats what i want.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Jass help

Post by weirdone2 »

Code: Select all

local integer array n
local integer array nn
local integer i=1
local integer l=1
local integer L=1
local integer K=1
local integer k=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 K>5
 loop
  exitwhen L>5
  loop
   exitwhen i>5
   if n[i] >= nn[K] then
    set nn[K]=n[i]
    set nn[0]=i
   endif
   set i=i+1
  endloop
  set k=nn[0]
  set n[k]=0
  set l=l+1
  set L=L+1
  set nn[0]=0
  set i=0
 endloop
 set l=1
 set L=1
 set K=K+1
endloop
call DisplayTextToForce( GetPlayersAll(), (nn[5]+nn[4]+nn[3]+nn[2]+nn[1] ))


Well here yo go, still untested so if you find any bugs let me know, and i used aeros code to make mine more efficient. I'm still king of inefficient jass though. ^^

Edit: btw heres an ex. of what this shoud display ex. you rand 13,3,10,6,4 it will output 3461013.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Jass help

Post by Aero »

1. What is "bubble sort" ?
2. You said you already have your numbers--Where are they?
--> By this did you mean

function sort takes integer dummy returns nothing ?

(Where "dummy" is something like 26374? Want THAT sorted?)
Gwypaas
Junior Member
Posts: 36
Joined: May 13th, 2007, 5:56 pm

Re: Jass help

Post by Gwypaas »

i want a trigger that gets 5 random values from 2-14 and then sorts the value up like if u get 1,8,4,10,3 it sorts it like 1,3,4,8,10.
Im sorry if u didnt understand. My english isnt that good cuz i comes from Sweden in europe