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

[Trigger] Big GUI 'AI' Problem!

Status
Not open for further replies.
Level 7
Joined
Jun 16, 2008
Messages
253
Well it's not trigger killing, but it's is crippling.

This trigger works in tandem with a number of abilities that allow a group of citizens to 'mine' wheat or ore from respective fields (to be improved), while another or other citizens collect the stored items from the storage granary and deposit it in the Town Hall.

The cycle goes like this:

There is a House, a Field, and Storage. A working citizen will use Set Home ability on House, then use Work on Field (all at the behest of Player), the citizen will go into field, animate mining for five seconds than recieve Ore/Wheat for their trouble, they immediately deposit it in random Storage within Range (just found a trigger to get ClosestUnit that I will use).
Then the citizen will go to House, pause, then begin the cycle over again on its own.

Meanwhile, another Citizen will have a Town Centre (Town Hall's have the ability to dub themselves Town Centres) and all he needs to do is use the Collect ability on Storage. Then he'll wait until there's an item, and then he'll grab all the items, and then deposit all the items in the Town Centre.

Problem is, he can grab them fine, but only deposits ONE instead of all items, the loop just kills itself. And there's no wait or anything in it, it's identical to previous loops that work perfectly. Could anyone help with this?

I've included the entire trigger just in case, but the relevant function is under the Collect comment heading, the bottom (third) function set.

Here's the trigger: Look near the bottom for the little loop integer B with the comments PROBLEM around it. That should give you a hint in the right direction. (Continued after trigger)

  • Villager AI Response
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
    • Actions
      • Custom script: local location l= null
      • Custom script: local unit farmer= null
      • Custom script: local unit storage= null
      • Custom script: local unit collector= null
      • -------- Set Home --------
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Ability being cast) Equal to (==) Set Home
            • ((Target unit of ability being cast) is A structure) Equal to (==) True
          • Then - Actions
            • Do Multiple ActionsFor each (Integer A) from 1 to 4, do (Actions)
              • Loop - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Integer A) Equal to (==) (Player number of (Owner of (Casting unit)))
                  • Then - Actions
                    • Set home[(Integer A)] = (Target unit of ability being cast)
                  • Else - Actions
          • Else - Actions
      • -------- Work --------
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Custom value of (Casting unit)) Equal to (==) 0
            • (Ability being cast) Equal to (==) Work
          • Then - Actions
            • Custom script: set l= GetSpellTargetLoc()
            • Custom script: set farmer= GetTriggerUnit()
            • Unit - Set the custom value of (Casting unit) to 1
            • Animation - Queue (Triggering unit)'s Animation - Stand Work animation
            • Wait until ((((Triggering unit) is in (Units within 70.00 of (Target point of ability being cast))) Equal to (==) True) or ((Custom value of (Triggering unit)) Equal to (==) 0)), checking every 0.10 seconds
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Triggering unit)) Equal to (==) 0
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
                  • Custom script: set l= null
                  • Custom script: set farmer= null
                  • Skip remaining actions
                • Else - Actions
            • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display Made it past Wait 1. Modify duration: Add 0.00 seconds and Don't wait
            • Unit - Order (Triggering unit) to Hold Position
            • Animation - Play (Triggering unit)'s Animation - Stand Work animation
            • Wait 5.00 game-time seconds
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Destructible-type of (Random destructible in (Region centered at (Position of (Triggering unit)) with size (200.00, 200.00)) matching ((Destructible-type of (Matching destructible)) Equal to (==) Wheat))) Equal to (==) Wheat
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display I found some Weet-B.... Modify duration: Add 0.00 seconds and Don't wait
                  • Hero - Create Weet-Bix and give it to (farmer)
                • Else - Actions
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Destructible-type of (Random destructible in (Region centered at (Position of (Casting unit)) with size (200.00, 200.00)) matching ((Destructible-type of (Matching destructible)) Equal to (==) Rock))) Equal to (==) Rock
                    • Then - Actions
                      • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display I found a rock!. Modify duration: Add 0.00 seconds and Don't wait
                      • Hero - Create Ore and give it to (farmer)
                    • Else - Actions
                      • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display I got nufin. Thanks.... Modify duration: Add 0.00 seconds and Don't wait
            • -------- I recently found out about polled waits. Game-time things are better than real-time. --------
            • Animation - Reset (Triggering unit)'s animation
            • Unit - Order (Triggering unit) to Move To (Position of (Random unit from (Units within 2000.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to (==) Storage))))
            • Wait until (((Integer((Distance between (Position of (Triggering unit)) and (Position of (Random unit from (Units within 2000.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to (==) Storage))))))) Less than or equal to (<=) 150) or (, checking every 0.10 seconds
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Triggering unit)) Equal to (==) 0
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
                  • Custom script: set l= null
                  • Custom script: set farmer= null
                  • Skip remaining actions
                • Else - Actions
            • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display Made it past Wait 2. Modify duration: Add 0.00 seconds and Don't wait
              • Do Multiple ActionsFor each (Integer A) from 1 to 6, do (Actions)
                • Loop - Actions
                  • Unit - Order (Triggering unit) to Give (Random unit from (Units within 500.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to (==) Storage))) to (Item carried by (Triggering unit) of type Weet-Bix)
                  • Unit - Order (Triggering unit) to Give (Random unit from (Units within 500.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to (==) Storage))) to (Item carried by (Casting unit) of type Ore)
            • Wait 0.10 game-time seconds
            • Unit - Order (Triggering unit) to Move To (Position of home[(Player number of (Owner of (Triggering unit)))])
            • Wait until (((Integer((Distance between (Position of (Triggering unit)) and (Position of home[(Player number of (Owner of (Triggering unit)))])))) Less than or equal to (<=) 150) or ((Custom value of (Triggering unit)) Equal to (==) 0)), checking every 0.10 seconds
            • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display Made it past Wait 3. Modify duration: Add 0.00 seconds and Don't wait
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Triggering unit)) Equal to (==) 0
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
                  • Custom script: set l= null
                  • Custom script: set farmer= null
                  • Skip remaining actions
                • Else - Actions
            • Unit - Order (Triggering unit) to Stop
            • -------- if still don't work, switch to integer b --------
              • Do Multiple ActionsFor each (Integer A) from 1 to 6, do (Actions)
                • Loop - Actions
                  • Unit - Order (Triggering unit) to Give home[(Player number of (Owner of (Triggering unit)))] to (Item carried by (Triggering unit) of type Weet-Bix)
                  • Unit - Order (Triggering unit) to Give home[(Player number of (Owner of (Triggering unit)))] to (Item carried by (Triggering unit) of type Ore)
            • Unit - Set the custom value of (farmer) to 0
            • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display And you are there!. Modify duration: Add 0.00 seconds and Don't wait
            • Wait 0.10 game-time seconds
            • Unit - Order (Triggering unit) to (Order(absorb)) (l)
            • Custom script: set l= null
            • Custom script: set farmer= null
          • Else - Actions
      • -------- Collect --------
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Custom value of (Triggering unit)) Equal to (==) 0
            • (Unit-type of (Target unit of ability being cast)) Equal to (==) Storage
            • (Ability being cast) Equal to (==) Collect
          • Then - Actions
            • Custom script: set storage= GetSpellTargetUnit()
            • Custom script: set collector= GetTriggerUnit()
            • Unit - Set the custom value of (Triggering unit) to 1
            • Cinematic - Send transmission to (All players) from (collector) named Collector: Play No sound and display Hi-ho! Hi-Ho! It's .... Modify duration: Add 0.00 seconds and Don't wait
            • Unit - Order (collector) to Stop
            • Wait until (((Storage 0296 <gen> has an item of type Weet-Bix) Equal to (==) True) or ((Custom value of (Triggering unit)) Equal to (==) 0)), checking every 0.10 seconds
            • Cinematic - Send transmission to (All players) from (collector) named Collector: Play No sound and display Wait 1 Passed. Modify duration: Add 0.00 seconds and Don't wait
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Triggering unit)) Equal to (==) 0
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
                  • Custom script: set storage= null
                  • Custom script: set collector= null
                  • Skip remaining actions
                • Else - Actions
            • Unit - Order (collector) to Move To (Position of (storage))
            • Wait until ((((Triggering unit) is in (Units within 150.00 of (Position of Storage 0296 <gen>))) Equal to (==) True) or ((Custom value of (Triggering unit)) Equal to (==) 0)), checking every 0.10 seconds
            • Cinematic - Send transmission to (All players) from (collector) named Collector: Play No sound and display Wait 2 Passed. Modify duration: Add 0.00 seconds and Don't wait
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Casting unit)) Equal to (==) 0
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
                  • Custom script: set storage= null
                  • Custom script: set collector= null
                  • Skip remaining actions
                • Else - Actions
              • Do Multiple ActionsFor each (Integer A) from 1 to 6, do (Actions)
                • Loop - Actions
                  • Unit - Order (storage) to Give (Triggering unit) to (Item carried by (storage) in slot (Integer A))
            • Wait 0.10 game-time seconds
            • Unit - Order (Triggering unit) to Move To (Position of Town_Hall[(Player number of (Owner of (Triggering unit)))])
            • Wait until (((Integer((Distance between (Position of (Triggering unit)) and (Position of Town_Hall[(Player number of (Owner of (Triggering unit)))])))) Less than or equal to (<=) 250) or ((Custom value of (Triggering unit)) Equal to (==) 0)), checking every 0.10 seconds
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Triggering unit)) Equal to (==) 0
                • Then - Actions
                  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
                  • Custom script: set storage= null
                  • Custom script: set collector= null
                  • Skip remaining actions
                • Else - Actions
            • -------- PROBLEM --------
              • Do Multiple ActionsFor each (Integer B) from 1 to 6, do (Actions)
                • Loop - Actions
                  • Unit - Order (Triggering unit) to Give Town_Hall[(Player number of (Owner of (Triggering unit)))] to (Item carried by (Triggering unit) in slot (Integer B))
            • -------- PROBLEM --------
            • Unit - Set the custom value of (Triggering unit) to 0
            • Cinematic - Send transmission to (All players) from (collector) named Collector: Play No sound and display I'm done!. Modify duration: Add 0.00 seconds and Don't wait
            • Wait 1.00 game-time seconds
            • Custom script: call IssueTargetOrderById( collector, OrderId("harvest"), storage )
            • Custom script: set storage= null
            • Custom script: set collector= null
          • Else - Actions
      • Custom script: set l= null
      • Custom script: set farmer= null
      • Custom script: set storage= null
      • Custom script: set collector= null
See it? For some reason, while that little shiny loop trigger works perfectly every previous time, nada for this one. The little collector citizen only drops one item at the Town Hall, instead of all. Can anyone shed some light on this please? I'll give a billion rep cookies!

Maybe it's stuffed up because there's another loop integer in the same trigger, and for some reason me using custom scripts has fluffed it up. ??? I really have no idea.

Also, I realise that the trigger must look a mess, but I've only had one night's study of JASS so am just learning. Puh-lease hulp!
 
Hmm... Perhaps it overloads? Ive had simple triggers that dont work I just add something like
  • Wait 0.10 game-time seconds
at the end of the loop and it works fine for me.

Or if that is too long do something like .01 seconds.
Computers calculate very quickly, and that is an order, says order unit to drop item NOW 6 times before it has chance to respond, possibly the last order is the only one the unit 'hears' as if you told a unit to move to 6 places at the same time he would move toward the last one you told him to move to.

Btw what item slot is the unit actually returning?
 
Level 7
Joined
Jun 16, 2008
Messages
253
I tried that too. I had waits all over the place, for 1 second just to check. There's no logical reason for it, unless there is some collusion between the first loop integer and the problem one, which is why I tried to circumvent it with loop integer b instead of a. No luck.
I learned about that when I used this loop function thingy the first time, where the unit didn't have time to give all its units.

It's returning all of them. The loop goes 1 to 6 (Integer Bs), and for every integer it will tell the unit to give the item in corresponding slot to the Town Hall.
I've tried this numerous different ways, from 1 to 6 give itemtype Wheat to Town Hall, to just copy pasting give Wheat to Townhall 6 times.

It works when telling the unit to drop the items.
The problem just seems to be with the whole function itself, something is getting messed up in the programming.

If anyone is interested in helping me with the problem, please follow the link in my sig to RPG Myriad where I have the map. It was created via JassNewGen 1.5.

I'll keep trying. I'm gonna flick that Custom value and Transmission to after the wait, in case they are interfering.

Btw, so you know, all those If/Then/Elses in the trigger are safety nets, (which hasn't been fully implemented) so that if a Player redirects the unit, or they are interrupted in some way, their custom value will go back to 0 (idle) and the trigger will be cancelled for them. But they aren't relevant to the problem.

The unit will go back and forward between the Storage and the Town Hall, completing the entire trigger (I checked with the transmissions) just the loop only goes once.
In fact, you know what I'll do, I think I'll make the loop and exitwhen custom script, that might work.

EDIT: Hang on, did you say at the end of the loop? Do you mean literally the last action in the loop, or just after the loop?
Can you stick a game-time wait in a loop? I haven't tried that, I just assumed you couldn't. Can you? Can you?
 
Level 7
Joined
Jun 16, 2008
Messages
253
Hey, I've pretty much solved it, just strung them out individually and stuck wait 0.01 between them.
But I would liike to know if any one could offer any insight as to why I couldn't just use the loop integer?
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
Your use of the local global trick is wrong.

Of course, I could tell you how, but the fact you don't know already means you don't know enough JASS to actually be able to use the trick and still debug your code, so really the best advice I can give is learn JASS, or at least don't use the local global trick.

You can put a wait in a loop, but if you're using GUI then it will be non-multi-instanceable.
 
Level 7
Joined
Jun 16, 2008
Messages
253
Fair enough, I am brand spanking new at the whole script code thing, I'm just proud the trigger goes at all!

Not to mention I'm confused just reading the words local and global strung together and what you are talking about in general.

And I WILL learn... so there! :p

I actually need the local globally thing for the trigger to work at all. I have someone else on team that knows JASS, he's just away for the mo.
However, hints never go amiss as they can help broaden my understanding. But that's purely voluntary as I wouldn't expect you to waste your time unecessarily in any case.

I'll be back... and loaded with JASS know how!
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Captain Griffen is right.
But is being a little harsh(as usual from what I have seen ;) )
About the "local global" variables bug: you can use it only once per trigger.
But I wonder are you using the bug? You seem to use "set l = null". If you were using the bug, you would have used udg_l.
I suggest you to download JNGP. The things you need to change about the trigger are all the GUI(not the custom script) lines where you use the variables.
 
Level 7
Joined
Jun 16, 2008
Messages
253
Lol, harshness is relative when it's all just text.
But anyway, I seriously, and embarrassingly don't know what you guys are really talking about with the 'bug'. Are you talking about the loop?

I kinda thought you have to go set l= null. I thought udg_l would be a pre-existing variable, though I suppose it makes sense for the WE to create it as a udg.
In the little snippets where it goes if customvalue is = 0, that's just my safety net in order that if the unit has been redirected from that task (causing it to go customvalue = 0), the trigger will be cancelled.
It this a dastardly abuse of custom script?

And lol, I just got JNGP (I'm assuming that stands for Jass New Gen Pack?), it's what I've been using to test and create my custom scripts. And it tells me if I made syntx errors and the like, so that can't be the problem.
The only issue (that I'm aware of aside from not being able to stick two GUI loops in) is that it could be leaking memory in some fashion.

I gather that the destroygroup in the custom script might aid this?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Just as I thought.
(there is a bug: if you have a global variable with name abc, and you initialize a local variable with name udg_abc, when you use the abc global variable in the GUI actions it will actually use the local; that is the local global trick Captain Griffen was referring to)
So you are trying to use locals in GUI? I assume you do not have globals with their names and all the GUI action lines in which you use those local variables have the JNGP Jass code?
 
Level 7
Joined
Jun 16, 2008
Messages
253
Had a bit of trouble understanding the last bit of that last sentence, think the grammar was wrong. But I have taken a peek at the map's script cose with JassCraft, when I first learned of the concept of writing triggers. (I simply had to try it, because when I saw the word local, I instantly saw the answer to my frustrated prayers in trying to do certain triggers)
Anyway... I'll see if I can write an answer that probably covers the question. I was trying to use locals in the fashion programmers designed them for. I have no knowledge of bugs occult or supernatural, and I vehemently deny anything but ignorance of said facts.
(I hate GUI custom script, it also stuffs up some of the unit locals I try to use because it sticks them in brackets. I had to fully write out certain bits to get around it.)

Did I clarify my ignorance enough? I could dig a little deeper...
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
I did not say ignorance :)
Yes you did.
But what I asked was this:
  • Cinematic - Send transmission to (All players) from (farmer) named Bob: Play No sound and display SKIP. Modify duration: Add 0.00 seconds and Don't wait
"from (farmer) named"
How did you come to have "farmer" there?
As normal GUI does not allow manual writing of names of variables.
My guess is that you used the JNGP feature that lets you insert custom scripts in GUI actions(the jass option from the drop down menu).
 
Level 7
Joined
Jun 16, 2008
Messages
253
Maybe I'm just oh so sneaky! ...
...
...
Or, yep I did use Jass thingy. It (was) all the same to me. And it seems to work fine, that was in fact the purpose of my little transmissions, to lemme know where and when it might stall.

Hey can I ask if your WE lets you do
Event- Generic Unit acquires a target.
???

Hey you know, I stuck that DestroyUnitGroup thingy on the end of trigger just to see what would happen. It's executes HEAPS. Even before I use the trigger!
Would you be able to sum up purpose of DestroyUnitGroup in the custom script presets.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
No, it does not.
It also does not allow for the event unit is damaged to be generic.
call DestroyGroup(Group'sName)
Destroys a unit group. Eh, think of it this way: most of the time when making triggers and stuff you create stuff( groups, effects, units etc). If you do not destroy/remove them they will still take up memory.
 
Status
Not open for further replies.
Top