• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Random Number... isn't random at all?

Status
Not open for further replies.
Level 6
Joined
Jul 2, 2008
Messages
156
So yeah as if my map doesn't have enough wrong with it already, something that is normally incredibly simple to me is giving me a hard time.

I have this variable, RandomBase, and I have it triggered to be a random number between 1 and 8.

But it always comes out 3.
Always.

So I rename it to RandomBaseP1 (to specifically handle player 1) and make another variable RandomBaseP2 (to specifically handle player 2).

RandomBaseP1 always comes out to 3 still,
and RandomBaseP2 always comes out to 8.

Any ideas?
 
Level 6
Joined
Jul 2, 2008
Messages
156
Okay I'm not really sure how to go about getting my triggers into text here. but I'll try.
Okay so I make this trigger run at the start.
  • Events
  • Conditions
  • Actions
  • Trigger - Run Base Randomizer P1
  • Wait until (RandomBaseFinishedP1 Equal to True), checking every 0.10 seconds)
  • Trigger - Run Base Randomizer P2
  • Wait until (RandomBaseFinishedP2 Equal to True), checking every 0.10 seconds)
And it goes on like that up to P8

  • Base Randomizer P1
  • Events
  • Conditions
  • Actions
  • Set NEWRandomBase = (Random integer number between 1 and 8)
  • Wait 0.10 seconds
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • RandomBaseFinishedP1 Equal to False
  • NEWRandomBase Equal to 1
  • BTaken1 equal to 9
  • Then - Actions
  • Set BTaken1 = (Player number of Player 1 (Red))
  • Set RandomBaseFinishedP1 = True
  • Skip Remaining Actions
Then I have the If part repeat for all 8 bases.
With a
  • Trigger - Run (This trigger) (checking conditions)
at the end.

NEWRandomBase is the variable I'm having the issues with, as its randomization result constantly comes out the same number. I made sure I don't use this variable in any other trigger prior to this one's activation.

BTaken is an integer value I apply to the individual bases, representing what number player should be getting the base. 9 means no player has been assigned to this base (the game crashes from player 0 so I chose 9)
 
Level 9
Joined
Apr 3, 2008
Messages
700
It won't work, you just repeat actions for the 1st player several times. And how BTaken1 can be equal to 9 if you have 8 players? try this trigger, and (replace the values of variables if they're wrong in it)
  • Actions
    • Custom script: local integer i=-1
    • Wait 0.10 seconds
    • Custom script: loop
    • Set NewRandomBase = (Random integer number between 1 and 8)
    • Custom script: set i=i+1
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • RandomBaseFinishedP1 Equal to False
        • NewRandomBase Equal to 1
        • BTaken1 Equal to 9
      • Then - Actions
        • Custom script: set udg_BTaken1 = GetConvertedPlayerId(Player(i))
        • Set RandomBaseFinishedP1 = True
        • Skip remaining actions
      • Else - Actions
    • Custom script: exitwhen i==7
    • Custom script: endloop
 
Level 6
Joined
Jul 2, 2008
Messages
156
Ehh your custom scripts are jibberish to me.
Could you explain 'em a bit?
I mean I understand loop and endloop, but why is the local integer -1 instead of 0?
And why two = in the exitwhen?

I'm probably understanding it wrong but it looks like it just loops itself 8 times.

There are 8 players, player 9 is an empty spot but the game at least is meant to recognize a player 9 so it prevents it from crashing.
 
Level 9
Joined
Apr 3, 2008
Messages
700
JASS:
Custom script: loop
Custom script: set i=i+1
<actions>
Custom script: exitwhen i==7
Custom script: endloop
Means that actions will repeat before variable i will become equal to 7,
JASS:
local variable i=-1
Sets the variable. You need "-1" because in jass player 1 (red) == player(0)

If you want this function to affect on 9th player, write not "exitwhen i==7" but "exitwhen i==8"
 
Level 6
Joined
Jul 2, 2008
Messages
156
Dude Dagguh, you save the day yet again lol.
<3
I would rep you again, but I can't rep you again recently lol.

Anyways about the custom scripts, I understand that its supposed to make it loop so many times, but I fail to see whats random about it.

The issue is in the
  • Set Variable Random
piece.

EDIT: After more trials... its still bugging up.
I put in a trigger to make the game immediately tell me what every random roll's outcome is, and the first number always turns out to be the same.

I put in another test trigger to manually randomize the number, and the outcomes are random each time. So I'm not sure why this is, but the game is absolutely determined to make the first roll always the same.

And it has nothing to do with the rest of the trigger. Just that first part REFUSES to randomize, or even give a different outcome.

EDIT 2: I made a 2nd integer variable to randomize parallel to the first variable, and it also always comes out to the same number.

I made the first variable randomize during initialization, then again during base randomization... both times the outcome STILL was the same number.

SOLUTION: After several hours of gazing at my triggers, baffled at what could possibly be causing this. At long last, all that was left that I hadn't tried was turning off the map's starting cinematic mode. I did this... and finally the number outcomes were random. HOW THIS IS SO I HAVE NO IDEA, but cinematic mode seems to stop the randomization process.

Several tests have confirmed this.
Man I would have never guessed.
 
Last edited:
Level 2
Joined
Sep 9, 2008
Messages
24
I had a similar problem in my map. Figured Warcraft III has a really shitty seed method, so I added a trigger which generates random numbers and doesn't use them whenever players take certain actions (typing, selecting units, issuing orders, etc...) this way, I'll get a psuedo-random amount of rolls so when a trigger does anything with random numbers, it won't roll the same thing every time.

Not sure if that would work for you, but it solved an issue I had.
 
Level 6
Joined
Jul 2, 2008
Messages
156
I had a similar problem in my map. Figured Warcraft III has a really shitty seed method, so I added a trigger which generates random numbers and doesn't use them whenever players take certain actions (typing, selecting units, issuing orders, etc...) this way, I'll get a psuedo-random amount of rolls so when a trigger does anything with random numbers, it won't roll the same thing every time.

Not sure if that would work for you, but it solved an issue I had.

It wouldn't work because the bases are given out right before players can do anything. I had thought about it though.
 
Level 2
Joined
Sep 9, 2008
Messages
24
You could make something based on several factors like the number of players in the game, the lengths of their names, the position in the alphabet of each letter in their names, etc, etc, etc...

Just find as much variable data as you can and use it to generate variable amounts of junk random numbers.

Could work, yes? :S
 
Level 6
Joined
Jul 2, 2008
Messages
156
You could make something based on several factors like the number of players in the game, the lengths of their names, the position in the alphabet of each letter in their names, etc, etc, etc...

Just find as much variable data as you can and use it to generate variable amounts of junk random numbers.

Could work, yes? :S

Hmm yeah I suppose your right, but if 2 players were to 1v1 several times they would have the same bases and such.

Anyhow my triggers worked, so I would like to declare this thread officially solved!
 
Status
Not open for further replies.
Top