HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Hmm how could I display random strings ?

09-10-2006, 02:30 AM#1
Fr0zenLord
Hmmph, How could I make my jass, randomly pick one of my local string's and display it? (and I mean randomly? XD? can anyone tell me this)
09-10-2006, 02:41 AM#2
shadow1500
Collapse JASS:
function RandomString takes nothing returns nothing
    local string array s
    local string randStr

    set s[0] = "ham"
    set s[1] = "banana"
    set s[2] = "cracker"
    set s[3] = "zomg"
    
    set randStr = s[GetRandomInt(0,3)]
    call DisplayTextToPlayer(Player(0),0,0,randStr)
endfunction
This function is using a local array to store its strings, then it selects one of them randomly and prints it on the screen.
09-10-2006, 04:33 AM#3
Fr0zenLord
Thank you very much...

Is there anyway I could get it to "Change" the letters?

Could I do this?
local string array a
local string a[0] = h
local string a[1] = a
local string a[2] = m
local string a[3] = (a[0]+a[1]+a[2]) but random, so it randomly mixes the letter
I want to make a sort of game.. were you must unscramble the letters
but I dont want everytime you play, the same letters in the same order
e.g
you play the game once, it shows hma as a string (you guess ham)
next time, I dont want it to be hma again next time to picks that string
I want it to change it so it could be ham, mah? ahm? etc... is it possible?
09-10-2006, 04:50 AM#4
PipeDream
funny, I saw this exact question yesterday.
Collapse JASS:
function shufflestring takes string in returns string
   local string array s
   local string out
   local integer n = StringLength(in)
   local integer i
   local integer r
   set i = 0
   loop
      exitwhen i>=n
      set s[i] = SubString(in,i,i+1)
      set i = i + 1
   endloop

   set out = ""
   set i = 0
   loop
      exitwhen i>=n
      set r = GetRandomInt(i,n-1)
      set out = out + s[r]
      set s[r] = s[i]
      set i = i + 1
   endloop

   return out
endfunction
09-10-2006, 05:30 AM#5
Fr0zenLord
Thanks heaps!


Collapse JASS:
function Trig_ShuffleString_Actions takes string in returns string
 local string array c
 local string out
 local integer n= StringLength(in)
 local integer i
 local string randStrmix
 local integer r
 set i = 0
    loop
        exitwhen i>=n
        set c[i] = SubString(in,i,i+1)
        set i = i + 1
    endloop


   set out = ""
   set i = 0

    loop
        exitwhen i>=n
        set r = GetRandomInt(i,n-1)
        set out = out + c[r]
        set c[r] = c[i]
        set i = i + 1
    endloop

    call DisplayTextToPlayer(Player(0),0,0,randStrmix)


    return out
endfunction

//===========================================================================
function InitTrig_ShuffleString takes nothing returns nothing
    set gg_trg_ShuffleString = CreateTrigger(  )
    call TriggerAddAction( gg_trg_ShuffleString, function Trig_ShuffleString_Actions )
endfunction

and how do I get it to call DisplayTextToPlayer(Player(0),0,0,randStrmix)

from this trigger (which sets all the words n stuff)

Collapse JASS:
function Trig_RandomString_Actions takes nothing returns nothing
 local string array a
 local string array b
 local string randStrmix
 
         
 set a[1] = "a"
 set a[2] = "b"
 set a[3] = "c"
 set a[4] = "d"
 set a[5] = "e"
 set a[6] = "f"
 set a[7] = "g"
 set a[8] = "h"
 set a[9] = "i"
 set a[10] = "j"
 set a[11] = "k"
 set a[12] = "l"
 set a[13] = "m"
 set a[14] = "n"
 set a[15] = "o"
 set a[16] = "p"
 set a[17] = "q"
 set a[18] = "r"
 set a[19] = "s"
 set a[20] = "t"
 set a[21] = "u"
 set a[22] = "v"
 set a[23] = "w"
 set a[24] = "x"
 set a[25] = "y"
 set a[26] = "z"
 set b[1] = (a[16]+a[14]+a[15]+a[5]) //Peon
 set b[2] = (a[7]+a[18]+a[21]+a[14]+a[20]) //grunt
 set b[3] = (a[8]+a[9]+a[16]+a[16]+a[15]+a[7]+a[18]+a[25]+a[16]+a[8])
 set b[4] = (a[7]+a[25]+a[18]+a[15]+a[3]+a[15]+a[16]+a[20]+a[5]+a[18])
 set randStrmix = b[GetRandomInt(1,4)]
  

endfunction

//===========================================================================
function InitTrig_RandomString takes nothing returns nothing
    set gg_trg_RandomString = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_RandomString, 1.00 )
    call TriggerAddAction( gg_trg_RandomString, function Trig_RandomString_Actions )
endfunction

I want it to shuffle the randStrmix string thing (which contains my b strings)
09-10-2006, 08:53 AM#6
blu_da_noob
You mustn't put it in a trigger. You must just put the function PipeDream posted into the custom script section of your map. Then in your trigger:
Collapse JASS:
  set randStrmix = shufflestring(randStrmix)
09-10-2006, 08:57 PM#7
Fr0zenLord
I see, Custom Script Code, theres only 1 problem now lol...
Thanks,

When I set, (I changed name again:P) randStr = shufflestring(randStr) I used caps and non caps... but it comes up with error expected variable name?
Collapse JASS:
function Trig_RandomString_Actions takes nothing returns nothing
 local string array a
 local string array b
 

         
 set a[1] = "a"
 set a[2] = "b"
 set a[3] = "c"
 set a[4] = "d"
 set a[5] = "e"
 set a[6] = "f"
 set a[7] = "g"
 set a[8] = "h"
 set a[9] = "i"
 set a[10] = "j"
 set a[11] = "k"
 set a[12] = "l"
 set a[13] = "m"
 set a[14] = "n"
 set a[15] = "o"
 set a[16] = "p"
 set a[17] = "q"
 set a[18] = "r"
 set a[19] = "s"
 set a[20] = "t"
 set a[21] = "u"
 set a[22] = "v"
 set a[23] = "w"
 set a[24] = "x"
 set a[25] = "y"
 set a[26] = "z"
 set b[1] = (a[16]+a[14]+a[15]+a[5]) //Peon
 set b[2] = (a[7]+a[18]+a[21]+a[14]+a[20]) //grunt
 set b[3] = (a[8]+a[9]+a[16]+a[16]+a[15]+a[7]+a[18]+a[25]+a[16]+a[8]) //hippogryph
 set b[4] = (a[7]+a[25]+a[18]+a[15]+a[3]+a[15]+a[16]+a[20]+a[5]+a[18]) //Gyrocopter
 

  set randStr = shufflestring(randStr)

endfunction

//===========================================================================
function InitTrig_RandomString takes nothing returns nothing
    set gg_trg_RandomString = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_RandomString, 1.00 )
    call TriggerAddAction( gg_trg_RandomString, function Trig_RandomString_Actions )
endfunction

09-10-2006, 09:35 PM#8
SentryIII
You took out randStr. Put it back!
09-10-2006, 11:09 PM#9
corvy
By that he means that there is no variable 'randStr'. You probably took it out and forgot to add back in "local string randStr".
09-10-2006, 11:09 PM#10
Fr0zenLord
-.- I know, I was fiddling with stuff... Still same error.
I put the ShuffleString into Custom Script Code, then
local string randStr

set randStr = ShuffleString(randStr)

same error. line 247... Expected a name... This erorr will haunt me:(

I fiddle around with stuff e.g trying
set randStr = b[randStr(1,4)]

I notice, if I take out one of the brackets for the numbers...
it comes up with the same error? is there something im suppost to be adding to
the shuffle string thing? like "Set randStr = ShuffleString(b) or something lol
I just cant figure this one out, i've tried like 100 times -.- it wont budge
everytime I save it says Error line 247. Expected a name :'(
09-10-2006, 11:19 PM#11
corvy
Then you forgot to put PipeDream's function in =P, or named it something else.
You can also put his function above that one in the trigger. (make sure they are seperate)
09-11-2006, 01:24 AM#12
Fr0zenLord
I did that corvy, but was told to put it in custom script:P theres nothing wrong that I can see

The code in my custom script = (I copy paste this, so its the same in my trig)

Collapse JASS:
function Trig_ShuffleString_Actions takes string in returns string
 local string array c
 local string out
 local integer n= StringLength(in)
 local integer i
 local integer r

 set i = 0
    loop
        exitwhen i>=n
        set c[i] = SubString(in,i,i+1)
        set i = i + 1
    endloop


   set out = ""
   set i = 0

    loop
        exitwhen i>=n
        set r = GetRandomInt(i,n-1)
        set out = out + c[r]
        set c[r] = c[i]
        set i = i + 1
    endloop  

    return out
endfunction

this is my trigger...(its currently disabled, as im adding names to strings..)
however the local string randStr is right,
then I set randStr = ShuffleString(randStr)
and ShuffleString is the exact name for the trigger in custom script so I dont understand why I get a "error, expected name" for setting the randStr = ShuffleString part
Collapse JASS:
function Trig_RandomString_Actions takes nothing returns nothing
 local string array a
 local string array b
 local string randStr
 
 
 set a[1] = "a"
 set a[2] = "b"
 set a[3] = "c"
 set a[4] = "d"
 set a[5] = "e"
 set a[6] = "f"
 set a[7] = "g"
 set a[8] = "h"
 set a[9] = "i"
 set a[10] = "j"
 set a[11] = "k"
 set a[12] = "l"
 set a[13] = "m"
 set a[14] = "n"
 set a[15] = "o"
 set a[16] = "p"
 set a[17] = "q"
 set a[18] = "r"
 set a[19] = "s"
 set a[20] = "t"
 set a[21] = "u"
 set a[22] = "v"
 set a[23] = "w"
 set a[24] = "x"
 set a[25] = "y"
 set a[26] = "z"
 set b[1] = (a[16]+a[14]+a[15]+a[5]) //Peon
 set b[2] = (a[7]+a[18]+a[21]+a[14]+a[20]) //grunt
 set b[3] = (a[8]+a[9]+a[16]+a[16]+a[15]+a[7]+a[18]+a[25]+a[16]+a[8]) //hippogryph
 set b[4] = (a[7]+a[25]+a[18]+a[15]+a[3]+a[15]+a[16]+a[20]+a[5]+a[18]) //Gyrocopter
 set b[5] = "acolyte"
 set b[6] = "archer"
 set b[7] = "paladin"
 set b[8] = "footman"
 set b[9] = "mortar team"
 set b[10] = "peasent"
 set b[11] = "ice troll"
 set b[12] = "knight"
 set b[13] = "rifleman"
 set b[14] = "gryphonrider"
 set b[15] = "priest"
 set b[16] = "sorceress"
 set b[17] = "siege engine"
 set b[18] = "spellbreaker"
 set b[19] = "dragonhawkrider"
 set b[20] = "raider"
 set b[21] = "tauren"
 set b[22] = "trollheadhunter"
 set b[23] = "demolisher"
 set b[24] = "kodobeast"
 set b[25] = "windrider"
 set b[26] = "trollbatrider"
 set b[27] = "trollwitchdoctor"
 set b[28] = "shaman"
 set b[29] = "spiritwalker"
 set b[30] = "shade"
 set b[31] = "abomination"
 set b[32] = "meatwagon"
 set b[33] = "gargoyle"
 set b[34] = "banshee"
 set b[35] = "necromancer"
 set b[36] = "obsidianstatue"
 set b[37] = "frostwyrm"
 set b[38] =
 set b[39] =
 set b[40] =
 set b[41] =
 set b[42] =
 set b[43] =
 set b[44] =
 set b[45] =
 set b[46] =
 set b[47] =
 set b[48] =
 set b[49] =
 set b[50] =
 set b[51] =
 set b[52] =
 set b[53] =
 set b[54] =
 set b[55] =
 set b[56] =
 set b[57] =
 set b[58] =
 set b[59] =
 set b[60] =
 set b[61] =
 set b[62] =
 set b[63] =
 set b[64] =
 set b[65] =
 set b[66] =
 set b[67] =
 set b[68] =
 set b[69] =
 set b[70] =
 set b[71] =
 set b[72] =
 set b[73] =
 set b[74] =
 set b[75] =
 set b[76] =
 set b[77] =
 set b[78] =
 set b[79] =
 set b[80] =
 set b[81] =
 set b[82] =
 set b[83] =
 set b[84] =
 set b[85] =
 set b[86] =
 set b[87] =
 set b[88] =
 set b[89] =
 set b[90] =
 set b[91] =
 set b[92] =
 set b[93] =
 set b[94] =
 set b[95] =
 set b[96] =
 set b[97] =
 set b[98] =
 set b[99] =
 set b[100] =
 set b[101] =
 set b[102] =
 set b[103] =
 set b[104] =
 set b[105] =
 set b[106] =
 set b[107] =
 set b[108] =
 set b[109] =
 set b[110] =
 set b[111] =
 set b[112] =
 set b[113] =
 set b[114] =
 set b[115] =
 set b[116] =
 set b[117] =
 set b[118] =
 set b[119] =
 set b[120] =
 set b[121] =
 set b[122] =
 set b[123] =
 set b[124] =
 set b[125] =
 set b[126] =
 set b[127] =

 
 
 set randStr = b[GetRandomInt(1,11)]
 call 

endfunction


//===========================================================================
function InitTrig_RandomString takes nothing returns nothing
    set gg_trg_RandomString = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_RandomString, 30.00 )
    call TriggerAddAction( gg_trg_RandomString, function Trig_RandomString_Actions )
endfunction

Please... help... Its 1 line... 1 error, and nothing that anyone has told me to do to actually get it to fit together has worked so far:/
:'(:'(:'(:'(
09-11-2006, 01:51 AM#13
SentryIII
The function you have there is called "Trig_ShuffleString_Actions" as opposed to "ShuffleString". That's why your trigger can't find it.
09-11-2006, 02:05 AM#14
Fr0zenLord
omg! you fixed it! tyvm!!! :)
now how would I get

it to display the 127 different words I have

set randStr = Trig_ShuffleString_Actions(randStr)
How would I add to that so it displays the words I have in my b array?
09-11-2006, 04:41 AM#15
SentryIII
Pass in one of the b[] strings into the function? After that, display randStr.