Randomized Number Help

TheTempest

New Member
Reaction score
6
I made PlayerIsles just a normal variable with no array elements and changed it in JASS so it's just udg_PlayerIsles.

Still get the undefined variables.

-----

I'm supposed to put this in the whole Custom Script section right? (when you click on the name of your map in the triggers window you get the custom scripts)
 

TheTempest

New Member
Reaction score
6
Maybe it's the "then" on the wrong line? JASS syntax checker can be like that.

I'm removing udg_PlayerIsles and making it a global. I remembered that if I ever need to access it I can just do
JASS:
function GetPlayerIsle takes integer iPlayerNum returns integer


EDIT: I just replaced it with a global and the parser said everything was fine. Hopefully it will work.
 

Summoned

New Member
Reaction score
51
I'm just saying

JASS:
if (iRand == udg_PlayerIsles[a])
then 
set IsTaken = true 
endif


did not compile for me, but

JASS:
if (iRand == udg_PlayerIsles[a]) then 
set IsTaken = true 
endif


did.
 

TheTempest

New Member
Reaction score
6
I'm just saying

JASS:
if (iRand == udg_PlayerIsles[a])
then 
set IsTaken = true 
endif


did not compile for me, but

JASS:
if (iRand == udg_PlayerIsles[a]) then 
set IsTaken = true 
endif


did.

Eh. Should of would of could of.

Now I am running into yet another wonderful problem.

I have my functions defined but when I do actions -> custom script "call GeneratePlayerIsle(udg_IntA)" I get a "GeneratePlayerIsle" undeclared function
 

Summoned

New Member
Reaction score
51
The way it's written (takes integer ?? returns integer), you'll want to do:

custom script: set udg_MyInt = GeneratePlayerIsle(udg_IntA)

where MyInt is a global integer variable, which you can then use. Unless you changed the function to something else altogether.

The error that you're getting implies the function you created doesn't exist, though. Not sure why.
 

TheTempest

New Member
Reaction score
6
Alright. Since this is giving me too much trouble I'm just going to post it so you guys can give it a thorough investigation.

Please don't rip anything off from this map as I am hoping to release it in the near future (once I get these JASS bugs worked out of course)
 

Attachments

  • Arkon Isles.w3x
    130.6 KB · Views: 169

Summoned

New Member
Reaction score
51
Yep, you changed the name. :p
JASS:
function GenerateIslandNumber takes integer iPlayerNum returns nothing

Also, it currently does nothing. You need to add a:
JASS:
set udg_PlayerIsles[iPlayerNum] = iRand

after the endloop. Or something like it.

EDIT: Also, this part can be simplified by using the "For Each Integer Variable" function instead of Integer A (fyi, you can call Integer A in JASS with bj_forLoopAIndex as well).
Trigger:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Set IntA = (Integer A)
      • Custom script: call GeneratePlayerIsle(udg_IntA)
      • Custom script: call DisplayTimedTextToForce(GetPlayersAll(), 30, "Player " + I2S(udg_IntA) + " was assigned the island " + I2S(PlayerIsles[udg_IntA]))

VVV
Trigger:
  • For each (Integer IntA) from 1 to 12, do (Actions)
    • Loop - Actions
      • Custom script: call GeneratePlayerIsle(udg_IntA)
      • Custom script: call DisplayTimedTextToForce(GetPlayersAll(), 30, "Player " + I2S(udg_IntA) + " was assigned the island " + I2S(PlayerIsles[udg_IntA]))
 

TheTempest

New Member
Reaction score
6
Yep, you changed the name. :p
JASS:
function GenerateIslandNumber takes integer iPlayerNum returns nothing

Also, it currently does nothing. You need to add a:
JASS:
set udg_PlayerIsles[iPlayerNum] = iRand

after the endloop. Or something like it.

EDIT: Also, this part can be simplified by using the "For Each Integer Variable" function instead of Integer A (fyi, you can call Integer A in JASS with bj_forLoopAIndex as well).
Trigger:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Set IntA = (Integer A)
      • Custom script: call GeneratePlayerIsle(udg_IntA)
      • Custom script: call DisplayTimedTextToForce(GetPlayersAll(), 30, "Player " + I2S(udg_IntA) + " was assigned the island " + I2S(PlayerIsles[udg_IntA]))

VVV
Trigger:
  • For each (Integer IntA) from 1 to 12, do (Actions)
    • Loop - Actions
      • Custom script: call GeneratePlayerIsle(udg_IntA)
      • Custom script: call DisplayTimedTextToForce(GetPlayersAll(), 30, "Player " + I2S(udg_IntA) + " was assigned the island " + I2S(PlayerIsles[udg_IntA]))

Thanks mate. I'll test it out now :D

EDIT: Nice it works perfectly :)

Thanks guys.
 

TheTempest

New Member
Reaction score
6
Arnold-Schwarzenegger-California-Bills.jpg


I'm Back

Take a look at this:

Trigger:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Game - Display to (All players) the text: (String((Integer A)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Player((Integer A))) slot status) Equal to Is playing [OFF]
          • ((Player((Integer A))) controller) Equal to User [OFF]
        • Then - Actions
          • Custom script: call GenerateIslandNumber(bj_forLoopAIndex)
          • Custom script: call DisplayTimedTextToForce(GetPlayersAll(), 30, "Player " + I2S(bj_forLoopAIndex) + " was assigned the island " + I2S(PlayerIsles[bj_forLoopAIndex]))
          • Custom script: set udg_tRegion = udg_Isles[PlayerIsles[bj_forLoopAIndex]]
          • Unit - Create 1 Select Your Race for (Player((Integer A))) at (Center of tRegion) facing Default building facing degrees
          • Set tRegion = No region
        • Else - Actions
          • Do nothing


Notice this: Game - Display to (All players) the text: (String((Integer A)))

It only loops about 4 - 5 times. The conditions in the IF statement are disabled right now, so you can ignore that part.
 

TheTempest

New Member
Reaction score
6
JASS:
globals
integer array PlayerIsles
endglobals

function GenerateIslandNumber takes integer iPlayerNum returns nothing

local integer iRand = GetRandomInt(1, 20)
local integer a = 0
local boolean IsTaken = false

// Don't do the loop if it's only player 1
if (iPlayerNum > 1) then

    loop
        set a = a + 1
        // If the random number matches one of the islands that have already
        // been taken then set istaken to true
        if (iRand == PlayerIsles[a]) then 
        set IsTaken = true 
        endif
        
        // After we have looped through all the players (a > iPlayerNum)
        // and there hasn't been a match then exit the loop and return iRand
        exitwhen (a == iPlayerNum and IsTaken == false)

        if(IsTaken == true) then

        // Reset our loop variable and generate a new number
        set a = 0
        set iRand = GetRandomInt(1, 20)

        endif
    endloop
    
endif
    
set PlayerIsles[iPlayerNum] = iRand
    
endfunction


The strange part is the amount of people it generates for changes every time. Sometimes its 2 and sometimes its 7
 

emootootoo

Top Banana
Reaction score
51
you forgot to set IsTaken to false when you reset the loop

also there are more efficient ways of doing it, but it doesn't matter for now
 

saw792

Is known to say things. That is all.
Reaction score
280
You are using Newgen, which means that you can use vJASS and thus free global declarations anywhere in your code:
JASS:
library Example initializer Init

  globals
    integer array PlayerIsles //Size isn't necessary
  endglobals

  function GetIslandNumber takes integer index returns integer
    return PlayerIsles[index]
  endfunction

  private function Init takes nothing returns nothing
    local integer i = 0
    local integer j = 0
    local integer rand = GetRandomInt(0, 19) //Start arrays at 0, convention
   
    loop
      exitwhen i == 12
      
      loop
        exitwhen j == i
        if rand == PlayerIsles[j] then
          set rand = GetRandomInt(0, 19)
          set j = 0
        else
          set j = j + 1
        endif
      endloop
      
      set PlayerIsles<i> = rand
      set rand = GetRandomInt(0, 19) //Not necessary, but will save some processing
      set j = 0
      set i = i + 1
    endloop
  endfunction

endlibrary</i>
 

TheTempest

New Member
Reaction score
6
Efficiency isn't really an issue as it's just a one time thing.

Also, the IsTaken issue with not reseting it fixed the problem. It randomizes everything correctly too :)
 

TheTempest

New Member
Reaction score
6
Efficiency isn't really an issue as it's just a one time thing.

Also, the IsTaken issue with not reseting it fixed the problem. It randomizes everything correctly too :)

@Saw792, you don't need the GetIslandNumber since PlayerIsles is a global and can be accessed anywhere (which is more efficient than calling a function)

EDIT: Sorry for the double post :(
 

saw792

Is known to say things. That is all.
Reaction score
280
Well I meant to make it private... but didn't. Oops. I'm just used to adding wrappers for array reads for public systems.

Anyway, what's the point of doing part of a trigger in jass, especially since it's only a one time thing? May as well save yourself looping outside of the function and do the actions at map initialisation (i.e. insert your region variable setting and CreateUnit() calls into the Init function I posted underneath the setting the PlayerIsles array). Makes it simpler for you and makes it more efficient anyway.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top