Jass

Chaos_Knight

New Member
Reaction score
39
1st:Im just started off with jass and tested a Ice Skating. lol. I think its beyonde(far) from my abilitys. This one saves and no errors at all.. But it wont work.. check it.
JASS:
function Trig_DanceFast_Actions takes nothing returns nothing
    local group g1
    local group g2
    local location p
    local location p2
    local unit u
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 5
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set g1 = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), 'Hpal')
        set u = GroupPickRandomUnit(g1)
        set p = GetUnitLoc(u)
        if ( IsUnitAliveBJ(u) == true ) then
            if ( GetTerrainTypeBJ(p) == 'Iice' ) then
                set p2 = PolarProjectionBJ(p,11, GetUnitFacing(u))
                call SetUnitPositionLoc( u, p2 )
                call RemoveLocation( p2 )
            endif
        endif
        call RemoveLocation( p )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction
function InitTrig_DanceFast takes nothing returns nothing
    set gg_trg_DanceFast = CreateTrigger(  )

    call TriggerRegisterTimerEventPeriodic( gg_trg_DanceFast, 0.02 )
    call TriggerAddAction( gg_trg_DanceFast, function Trig_DanceFast_Actions )
endfunction


2nd: I want it to enable when red types the message -medium
It doesnt effect. It is on initally off and i use the trigger
Trigger:
  • Trigger - Turn on DanceDa
Strange..
 

Tyman2007

Ya Rly >.
Reaction score
74
Add local integer A and B
Replace every bj_forLoopAIndex with A
Replace every bj_forLoopAIndexEnd with B

Looks better and it's more efficient.

I don't quite know what's going on.. Usually an unresponsive event is the cause.

Try having it display a message to see that the event is actually working. Put a message in every if, then, and else.

If all displays properly when it should, it's the actions or variables.
If only a couple displays, then a then or else block isn't being met
If none displays, then it's the event itself.
 

Nestharus

o-o
Reaction score
84
Yea... you need to clean up your code big time... like locations... etc... you aren't using z coordinates so no need for location handle at all...

Also, purple means native
red means function

functions just call natives, so you might want to click them and inline their code at the least : p.

atm with all of your BJ calls and bj vars, your code is very unfriendly to me ; ).

Once you make it readable, we'll go from there ; P
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
Here I made an Ice Skating for you...

JASS:
scope Slide initializer I
    globals
        private constant real SPEED   = 400.   //The Speed of the sliding
        private constant integer UNIT = 'Hpal' //The Rawcode of slider
        private constant integer ICE  = 'Iice' //Rawcode of ice tile
        private constant integer NUM  = 5      //Number of players
    endglobals

    private function Move takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real x = GetUnitX(u)+(SPEED/32)*Cos(GetUnitFacing(u)*bj_DEGTORAD)
        local real y = GetUnitY(u)+(SPEED/32)*Sin(GetUnitFacing(u)*bj_DEGTORAD)
        
        if GetTerrainType(GetUnitX(u),GetUnitY(u)) == ICE then
            call SetUnitX(u,x)
            call SetUnitY(u,y)
        endif
    endfunction

    private function A takes nothing returns nothing
        local group g = CreateGroup()
        local integer i = -1
        
        set bj_groupEnumTypeId = UNIT

        loop
            set i = i + 1
            call GroupEnumUnitsOfPlayer(g,Player(i),filterGetUnitsOfPlayerAndTypeId)
            call ForGroup(g,function Move)
            call GroupClear(g)
            exitwhen i == NUM-1
        endloop
        
        call DestroyGroup(g)
        
        set g = null
    endfunction

    //===========================================================================
    private function I takes nothing returns nothing
        local trigger g = CreateTrigger()
        call TriggerRegisterTimerEvent(g,.03125,true)
        call TriggerAddAction(g,function A)
        set g = null
    endfunction
endscope
 

Attachments

  • Slide.w3x
    11.9 KB · Views: 172

Prozix

New Member
Reaction score
7
You might want to move the units in the filter itself (you'll have to write it yourself) so you don't loop over the filtered units twice. Also

JASS:

//this loop format makes more sense in my opinion
    local integer i = 0
    loop
        // goes from 0 to bj_MAX_PLAYERS-1
        if SomeCondition then //if you want to stop looping
              set i = bj_MAX_PLAYERS //do something like this
        endif
        set i = i+1
        exitwhen i >= bj_MAX_PLAYERS // >= to make sure it stops, else you'd have to do set i = bj_MAX_PLAYERS-1 in the if statement
    endloop


I just thought that if you loop over every unit in the game with the filter, you don't have to do this for all players:

My suggestion:
JASS:

scope Slide initializer Init
globals
    //private constant real SPEED   = 400.   //The Speed of the sliding
    private constant real PERIOD  = 0.03125
    //private constant real TICK_SPEED = SPEED*PERIOD
    private constant integer TILE_ICE  = 'Iice' //Rawcode of ice tile
    
    private group GROUP = CreateGroup()
    private group G_Sliding = CreateGroup()
endglobals

private function MoveFilter takes nothing returns boolean
    local unit u = GetFilterUnit()
    local real facing = GetUnitFacing(u)*bj_DEGTORAD
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real speed = GetUnitMoveSpeed(u)*PERIOD
    if GetTerrainType(x, y) == TILE_ICE then
        call SetUnitPosition(u, x+speed*Cos(facing), y+speed*Sin(facing)) //use TICK_SPEED for a constant sliding speed
        if not(IsUnitInGroup(u, G_Sliding)) then //not sure if this is necessary
            call GroupAddUnit(G_Sliding, u)
            call PauseUnit(u, true)
        endif
    else
        if IsUnitInGroup(u, G_Sliding) then //not sure if this is necessary
            call GroupRemoveUnit(G_Sliding, u)
            call PauseUnit(u, false)
        endif
    endif
    set u = null
    return false
endfunction

private function Periodic takes nothing returns nothing
    call GroupEnumUnitsInRect(GROUP, bj_mapInitialPlayableArea, Filter(function MoveFilter))
endfunction

private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(), PERIOD, true, function Periodic)
endfunction
endscope

To test it, create a new map with the ice tile, makesome ice and units, add this trigger and voila. (This doesn't take collision into account)
 

Executor

I see you
Reaction score
57
JASS:
//this loop format makes more sense in my opinion
    local integer i = 0
    loop
        // goes from 0 to bj_MAX_PLAYERS-1
        if SomeCondition then //if you want to stop looping
              set i = bj_MAX_PLAYERS //do something like this
        endif
        set i = i+1
        exitwhen i >= bj_MAX_PLAYERS // >= to make sure it stops, else you'd have to do set i = bj_MAX_PLAYERS-1 in the if statement
    endloop

JASS:
if SomeCondition then //if you want to stop looping
   set i = bj_MAX_PLAYERS //do something like this
endif
// =>
exitwhen SomeCondition // ?!
 

Prozix

New Member
Reaction score
7
Yeah ofcourse, but the original condition was i>=bj_MAX_PLAYERS.
You could do this
JASS:
exitwhen i>=MAX_PLAYERS or SomeCondition

when SomeCondition is a boolean. If it's a big function used to do something in the loop it would be pretty useless to call it again in the exitwhen statement because it will (hopefully) return the same value.

But ofcourse you couldn't know what I ment when I posted that :p

Sometimes you want to know if the evaluation of the if was true at least once, then you'd have to use a boolean.

[SomeRandomExampleFromOneOfMyMaps]
JASS:
private function ButtonPress takes nothing returns boolean
    local item itm = GetSoldItem()
    local integer id = GetItemTypeId(itm)
    local integer i
    local boolean hit = false
    set i=0
    loop
        if notes<i>.used and notes<i>.y &lt; LANE_YTARGET+HIT_DISTANCE and notes<i>.y &gt; LANE_YTARGET-HIT_DISTANCE then
            if (id == ITEMID_REDBUTTON and notes<i>.lane == 0) or /*
            */ (id == ITEMID_GREENBUTTON and notes<i>.lane == 1) or /*
            */ (id == ITEMID_BLUEBUTTON and notes<i>.lane == 2) or /*
            */ (id == ITEMID_YELLOWBUTTON and notes<i>.lane == 3) then
                    call DestroyEffect(AddSpecialEffect(HIT_EFFECT, notes<i>.x, notes<i>.y))
                    call MakeTextTag(&quot;Good!&quot;, notes<i>.x, notes<i>.y, 150, 255, 150)
                    set hits = hits+1
                    call RemoveItem(itm)
                    set itm=null
                    call notes<i>.end()
                    set hit = true
            endif
        endif
        set i=i+1
        exitwhen i==notes.size or hit
    endloop
    
    if not(hit) then
        if id==ITEMID_REDBUTTON then
            set i = 0
        elseif id==ITEMID_GREENBUTTON then
            set i = 1
        elseif id==ITEMID_BLUEBUTTON then
            set i = 2
        elseif id==ITEMID_YELLOWBUTTON then
            set i = 3
        endif
        call MakeTextTag(&quot;Miss!&quot;, LANE_XMIN+i*2*TILE, LANE_YTARGET, 255, 150, 150)
        set misses = misses+1
    endif
    call ClearTextMessages()
    call BJDebugMsg(I2S(hits) + &quot;/&quot; + I2S(misses))
    return false
endfunction
</i></i></i></i></i></i></i></i></i></i></i></i>

[/SomeRandomExampleFromOneOfMyMaps]

EditEdit: After reading my code I came to the conclusion that there are some bug's in it, but it doesn't matter for the example its purpose
 

Executor

I see you
Reaction score
57
What about:

JASS:
if ... then
   ...
   exitwhen true
endif
exitwhen ...


instead of

JASS:
if ... then
   ...
   set hit = true
endif
exitwhen ... or hit


I know what you mean, but your examples can be solved on an easier way :p
For e.x. if you want to continue the loop execution till the 'main' exitwhen, cause there's important code on the way to it.
 

Prozix

New Member
Reaction score
7
You are a genius xD
JASS:
exitwhen true

would do the trick.
But if you don't want to quit immediately but you do want to know if the condition was true at least once, you should use a boolean right?

btw, I remember that a long time ago I've been searching for a break statement xD
 
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