• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Quick script question

Status
Not open for further replies.
Level 19
Joined
Aug 16, 2007
Messages
881
Hello. What's wrong with this script?

It's supposed to store five taverns into an unit array and randomize an integer to a number between 0 and 5 (0, 1, 2, 3, 4). Then it will remove all taverns, except the tavern that got the randomized numbers ID.

The problem is that none of the taverns is removed, all five is still there, visible and alive...


JASS:
function LoadRandomTavernMode takes nothing returns nothing
    local integer i = GetRandomInt(0, 4)
    local integer j = 0
    local unit array tempTavern
    set tempTavern[0] = gg_unit_n000_0012
    set tempTavern[1] = gg_unit_n006_0027
    set tempTavern[2] = gg_unit_n001_0013
    set tempTavern[3] = gg_unit_n00V_0115
    set tempTavern[4] = gg_unit_n02F_0153

    loop
    exitwhen (j >= 5)

    if (j != i) then
    call ShowUnit( tempTavern[j], false )
    call KillUnit( tempTavern[j] )
    endif

    set j = j + 1
    endloop

    set tempTavern[0] = null
    set tempTavern[1] = null
    set tempTavern[2] = null
    set tempTavern[3] = null
    set tempTavern[4] = null
endfunction


And by the way, will this function randomize to one of those numbers: 0, 1, 2, 3, 4?
JASS:
    local integer i = GetRandomInt(0, 4)
or is it supposed to be 5 and not 4?

One more question. How to remove the BJ?

Thanks.
 
Last edited:
Level 19
Joined
Aug 16, 2007
Messages
881

  • MainGameMode RandomTavern
    • Events
      • Player - Player 1 (Red) types a chat message containing -rt as An exact match
      • Player - Player 2 (Blue) types a chat message containing -rt as An exact match
      • Player - Player 3 (Teal) types a chat message containing -rt as An exact match
      • Player - Player 4 (Purple) types a chat message containing -rt as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -rt as An exact match
      • Player - Player 7 (Green) types a chat message containing -rt as An exact match
      • Player - Player 8 (Pink) types a chat message containing -rt as An exact match
      • Player - Player 9 (Gray) types a chat message containing -rt as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -rt as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -rt as An exact match
    • Conditions
      • GameModePicked Equal to False
      • (Triggering player) Equal to Host
    • Actions
      • Custom script: call LoadRandomTavernMode()
      • -------- - - - - - - --------
      • Cinematic - Clear the screen of text messages for (All players)
      • -------- - - - - - - --------
      • Set WhatMainGameMode[3] = True
      • Set GameModePicked = True
      • Set GameMode_EnableRepick = False
      • -------- - - - - - - --------
      • Trigger - Run StopGameModeTimer <gen> (checking conditions)
      • Game - Display to (All players) for 10.00 seconds the text: |cff008080Game|r: |...
      • Game - Display to (All players) for 10.00 seconds the text:
      • -------- - - - - - - --------
      • For each (Integer ForLoopInteger[0]) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set p = (Player(ForLoopInteger[0]))
          • Set i = ForLoopInteger[0]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • i Not equal to 6
                  • i Not equal to 12
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (p controller) Equal to User
                  • (p slot status) Equal to Is playing
                • Then - Actions
                  • Set TempPoint[0] = (Random point in SpawnHeroSelecter <gen>)
                  • Unit - Create 1 Lost Soul for p at TempPoint[0] facing Default building facing degrees
                  • Set HeroSelecter[i] = (Last created unit)
                  • Camera - Pan camera for p to TempPoint[0] over 0.00 seconds
                  • Custom script: call RemoveLocation(udg_TempPoint[0])
                • Else - Actions
            • Else - Actions
      • -------- - - - - - - --------
      • Trigger - Run CreateMultiboardForGame <gen> (checking conditions)
      • Trigger - Turn on UpdateTheMultiboard <gen>
      • Cinematic - Fade in over 2.00 seconds using texture Black Mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • -------- - - - - - - --------
      • Custom script: call DestroyTrigger(gg_trg_MainGameMode__AllPick)
      • Custom script: call DestroyTrigger(gg_trg_MainGameMode__AllRandom)
      • Custom script: call DestroyTrigger(gg_trg_MainGameMode__RandomTavern)



The message is displayed in-game and everything else works... But the function seems not to be called...
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Weird. I tested like this and it worked.

  • Untitled Trigger 010
    • Events
      • Player - Player 1 (Red) types a chat message containing p as An exact match
    • Conditions
    • Actions
      • Custom script: call XXXActions()
      • Game - Display to Player Group - Player 1 (Red) the text: Ended
Can you post a test map?
 
Level 19
Joined
Aug 16, 2007
Messages
881
Hm... Maybe it's something weird with my World Editor then? I could have posted a test map, but then I'll have to post the whole map and I don't really think Drunken_Rider wants that. I'll try do the same in another map and I'll tell you if it works there.


Edit: Does still not work, not even in the new test map I made. I'll upload it here, please take a look... :)
View attachment TestMap.w3x
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
I'll check this one out.

EDIT:

This gives syntax errors:

JASS:
    set tempTavern[0] = gg_unit_hfoo_0004
    set tempTavern[1] = gg_unit_hfoo_0000
    set tempTavern[2] = gg_unit_hfoo_0001
    set tempTavern[3] = gg_unit_hfoo_0002
    set tempTavern[4] = gg_unit_hfoo_0003

Guess it don't want to set preplaced units into a variable. Create them instead and set them into a variable in the function.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
When trying to save it with JNGP, it says the gg_units are undeclared variables.

I added a trigger like this and then it worked:
  • Untitled Trigger 002
    • Events
    • Conditions
    • Actions
      • Set u1 = Footman 0004 <gen>
      • Set u1 = Footman 0000 <gen>
      • Set u1 = Footman 0001 <gen>
      • Set u1 = Footman 0002 <gen>
      • Set u1 = Footman 0003 <gen>
Is it for a campaign? If it's not, just make it a library, use normal trigger not the header:

JASS:
library Tavern

function LoadRandomTavernMode takes nothing returns nothing
    local integer i = GetRandomInt(0, 4)
    local integer j = 0
    local unit array tempTavern
    set tempTavern[0] = gg_unit_hfoo_0004
    set tempTavern[1] = gg_unit_hfoo_0000
    set tempTavern[2] = gg_unit_hfoo_0001
    set tempTavern[3] = gg_unit_hfoo_0002
    set tempTavern[4] = gg_unit_hfoo_0003

    loop
    exitwhen (j >= 5)

    if (j != i) then
    call ShowUnit( tempTavern[j], false )
    call KillUnit( tempTavern[j] )
    endif

    set j = j + 1
    endloop

    set tempTavern[0] = null
    set tempTavern[1] = null
    set tempTavern[2] = null
    set tempTavern[3] = null
    set tempTavern[4] = null
endfunction

endlibrary
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
Your library example do not work, I tested it myself too putting it into a library. Arrayed variables takes a lot more space than normal atleast booleans.


As I found it myself that points and booleans shouldnt be arrayed if you use a few of 'em as they take less space that way.
Vexorian said:
well If I used an array it would 4*8129 bytes if I use 5 variables it would use 20 bytes
 
Status
Not open for further replies.
Top