Randomized Number Help

TheTempest

New Member
Reaction score
6
Randomized Number Help [FIXED]

Hey guys. In my map there are 20 islands and 12 players. I want to give each player an island, but randomize it so it's different each time (keeps things fresh).

The problem I'm running into is that 2 players can't have the same island.

I need some sort of way to get this right. The only thing I thought which MIGHT work is just looping until it finds an island that isn't taken up. Of course, this is really inefficient.

If you can do it in GUI I would prefer it (I code in a lot of languages but I don't know JASS. How ironic :rolleyes:)

Thanks
 
You didn't mention how you're "giving" the player an island, but let's just say you're spawning a unit there, you should create a dummy unit, or if you already have one create another one called Island Dummy and create one per island (via world editor) then in your trigger where you're giving the islands set the actions up like that:

set tempgroup = units in (entire map) matching (matching unit) equal to Island Dummy
for each integer from 1 to 12 do
loop
set tempunit = random unit from temgroup
remove tempunit from tempgroup
set temppoint = position of tempunit
create 1 peasant for player(integer a) at temppoint
custom script: call RemoveLocation(udg_temppoint)
>outside the loop
custom script: call DestroyGroup(udg_tempgroup)
 
You didn't mention how you're "giving" the player an island, but let's just say you're spawning a unit there, you should create a dummy unit, or if you already have one create another one called Island Dummy and create one per island (via world editor) then in your trigger where you're giving the islands set the actions up like that:

set tempgroup = units in (entire map) matching (matching unit) equal to Island Dummy
for each integer from 1 to 12 do
loop
set tempunit = random unit from temgroup
remove tempunit from tempgroup
set temppoint = position of tempunit
create 1 peasant for player(integer a) at temppoint
custom script: call RemoveLocation(udg_temppoint)
>outside the loop
custom script: call DestroyGroup(udg_tempgroup)

Maybe I wasn't very clear.

I have an int variable PlayerIsles[12] and each element holds the Island # (1-20)

Problem I'm having is that if Player 1 is assigned 3 so PlayerIsles[1] = 3 and Player 2 is assigned 3 then PlayerIsles[2] = 3.

Once the randomizing is finished each player gets a builder at that location so obviouslly you can't have 2 players with the same location.

If I knew JASS i could just do While(tRandNum != PlayerIsles[1] && tRandNum != PlayerIsles[2] etc.)
 
That's exactly what I told you to do, you have unit groups here which makes it easier for you to code stuff, you don't need to use integers like in other languages, just look again at my previous post
 
That's exactly what I told you to do, you have unit groups here which makes it easier for you to code stuff, you don't need to use integers like in other languages, just look again at my previous post

I'd prefer to use integers, they take up less memory than creating dummy units.
 
o_O well if creating dummies is a problem for you just remove them from the game, which is a total removal of the unit, after you've used them for their purpose..

If you wish to use integers so badly, then simply remove the given isle from the isles variable, example

Isles[1-20] // are your islands
PlayerIsles[1-12] // are the isles that are supposed to be given
IslesCount // is the count of current isles available (Not an Array)
Isle // Integer Variable (Not an Array)

For each integer B from 1 to 12 do
loop
Set Isle = Random number between 1 and IsleCount // This sets the random isle, let's say it's 5
Set PlayerIsles[Integer B] = Isle // Now you need to set the IslesCount to -1
Set IslesCount = IslesCount -1 // Done
For each integer A from Isle to IslesCount // you need to loop through all isles and downgrade them by 1
loop
Set Isles[Integer A] = Isles[Integer A + 1] // now Isle 5 (which I chose to be the random number) becomes Isle 6 and so on, isle 20 becomes isle 19 and the max number of isles becomes 19

I hope you get the idea
 
o_O well if creating dummies is a problem for you just remove them from the game, which is a total removal of the unit, after you've used them for their purpose..

If you wish to use integers so badly, then simply remove the given isle from the isles variable, example

Isles[1-20] // are your islands
PlayerIsles[1-12] // are the isles that are supposed to be given
IslesCount // is the count of current isles available (Not an Array)
Isle // Integer Variable (Not an Array)

Set Isle = Random number between 1 and IsleCount // This sets the random isle, let's say it's 5
Set PlayerIsles[1] = Isle // Now you need to set the IslesCount to -1
Set IslesCount = IslesCount -1 // Done
For each integer A from Isle to IslesCount // you need to loop through all isles and downgrade them by 1
loop
Set Isles[Integer A] = Isles[Integer A + 1] // now Isle 5 (which I chose to be the random number) becomes Isle 6 and so on, isle 20 becomes isle 19 and the max number of isles becomes 19

I hope you get the idea

I downloaded the NewGen pack and JASS is retarded easy. Thanks for trying, Manix. I'll report back when I get some working code (Writing it in JASS is going to be so much easier than GUI when I can use exitwhen)
 
Alrightie, what I posted above is the system, if I can call it that way, to pick random stuff by integers, I highly believe it's based off the same idea in jass aswell ;)
 
Fuck JASS syntax.

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


You have to put udg_ before any global variable, correct?

PlayerIsles is an integer array, so I call it using usg_PlayerIsles[] ?
 
whether it is an array or not it's still udg_VarName which stands for UserDefinedGlobal, in jass variables are of two types, globals and locals but for more info you should refer to the jass section
 
whether it is an array or not it's still udg_VarName which stands for UserDefinedGlobal, in jass variables are of two types, globals and locals but for more info you should refer to the jass section

I know that. That's the code I have and it's saying that udg_PlayerIsles is an undefined variable (no it isn't)
 
What is this udg_PlayerIsles[a]

JASS:
function GenerateIslandNumber takes integer iPlayerNum returns integer

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

    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 == udg_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
        
        // This is only called if the exitwhen condition was false
        if(a > iPlayerNum) then

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

        endif
    endloop

return iRand

endfunction


"udg_PlayerIsles undefined variable."

In my variable editor: "PlayerIsles : Integer : Array[12]"
 
What is this udg_PlayerIsles[a]

JASS:
function GenerateIslandNumber takes integer iPlayerNum returns integer

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

    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 == udg_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
        
        // This is only called if the exitwhen condition was false
        if(a > iPlayerNum) then

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

        endif
    endloop

return iRand

endfunction


"udg_PlayerIsles undefined variable."

In my variable editor: "PlayerIsles : Integer : Array[12]"

EDIT: Sorry for the double post.
 
Try setting the Array Size to 1 in the object editor. The Size stands for something very different than what you'd expect Array Size to mean.
 
Well Idk, You could've done what I suggested, it works I've used that system for an AoS -ar command
 
Well try stuff out, try changing it, changing the array capacity, as already suggested, try creating a different variable and using it, try setting it in the same function see what does what

EDIT: I'm goin to bed nao, I wish you good luck on fixing your code, will respond back tomorrow if it's still an issue
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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