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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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