• 🏆 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!

Order Tracking - Submission

Status
Not open for further replies.
This is my first submission, hopefully is all alright.

Edit: Changed subscription to condition instead of action, as MyPad suggested

JASS:
scope OrderTracking initializer Init
    private function Action takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local integer orderId = GetIssuedOrderId()
       
        local string unitName = GetUnitName(u)
        local string orderName = OrderId2String(orderId)
        local string targetName = GetObjectName(orderId)
        local string targetUnitName = GetUnitName(GetOrderTargetUnit())
       
        // If orderName is empty, replace it with tragetName
        if (orderName == "" and targetName != "Default string") then
            set orderName = targetName
        // If orderName is not empty, just append targetName
        elseif (targetName != "Default string") then
            set orderName = orderName + " " + GetObjectName(orderId)
        // If remaining string is "Default string" then do not print it
        elseif (orderName == "Default string") then
            set orderName = ""
        endif
       
        // Always add targetUnitName if it exists
        if (targetUnitName != "Default string") then
            set orderName = orderName + " " + targetUnitName
        endif
       
        call BJDebugMsg(unitName + " - (" + I2S(orderId) + ") " + orderName)
       
        set u = null
        return TRUE
    endfunction
   
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
       
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_ORDER)
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER)
       
        call TriggerAddCondition(t, Condition(function Action))
        set t = null
    endfunction
endscope
 

Attachments

  • Order Tracking.w3x
    17.3 KB · Views: 52
Last edited:
Hello. This seems like a nice submission, but I would suggest converting this..

JASS:
    call TriggerAddAction(t, function Action)

into this.
JASS:
    call TriggerAddCondition(t, Condition(function Action))

Aside from that, everything is fine. If you're wondering why I'm suggesting to convert that into a triggercondition, thinking that it wouldn't work, then it's because expressions that return nothing will somehow return something when converted into a filterfunc or conditionfunc.
 
Level 14
Joined
Mar 11, 2017
Messages
587
@RoflingAtU From the HelpMe section, have a look at the tutorial Converting GUI into Efficient JASS look for the intervention of Almia and the update of the final part of the tutorial that followed.
Almia said:
Ask them to merge the conditions and actions and use conditions rather than action for triggers.
Actions creates new thread, conditions don't.
That being said about the reason to merge AddAction to AddCondition, I have little defined concept of what a thread concretely is beside being a queue of related actions. Also unclear to me is if a thread is an entity handled by a processor, a virtual machine, or an OS, or none of those or even all of them in some way. Surely others can explain properly.
 
With the submission being solved, I would just suggest changing the return function of the conditionfunc from boolean to nothing, removing the return value of the function. It will silently return a true statement.

@RoflingAtU From the HelpMe section, have a look at the tutorial Converting GUI into Efficient JASS look for the intervention of Almia and the update of the final part of the tutorial that followed.

That being said about the reason to merge AddAction to AddCondition, I have little defined concept of what a thread concretely is beside being a queue of related actions. Also unclear to me is if a thread is an entity handled by a processor, a virtual machine, or an OS, or none of those or even all of them in some way. Surely others can explain properly.

From what I know and recall, a thread is something that is handled by the JASS VM. It has a limit of 300 000 operations.
A TriggerCondition retains the thread (perhaps refreshing the operation count) while a TriggerAction creates a new thread (allowing for TriggerSleepActions).
 
Level 2
Joined
Jul 8, 2017
Messages
5
? how can u ever ask non-existant object? Trigger is a container which stores all the actions and conditions in linked list style, so if the list is empty, obviously it won't call anything but actions directly
 
It won't be called, but there might be other operations that might be executed when a trigger runs. I'm curious if same amount of operations run in background when a condition runs, or when an action runs. Maybe we still call some redundancy, when we execute the action -- at least that's my question. But again, as said, this is/was a pseudo reason.
 
So out of curiosity now:

-- conditionCounter_Check()
-- -- (if true) -> conditions_loop()
-- actionCounter_Check()
-- -- (if true) -> actions_loop()

and in case condition_loop Returns false, then no actionCounter_Check() does run at all, I guess?
So potentialy we save one action_Counter check for now when we use conditions? Is there maybe more checks? just in case you know.
 
Status
Not open for further replies.
Top