• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Variables?

Status
Not open for further replies.
Level 5
Joined
Aug 6, 2009
Messages
136
Hey everyone.

I was up to doing a trigger like.

When both units have as an example:

2 Kaels are bosses and when they BOTH have X Life they will teleport away.

I just dont know how to fix so they both teleport when they have like X life left.

Do i have to use Variables for this? If so,then what type of it?

Help? :s
 
Level 18
Joined
Feb 28, 2009
Messages
1,971
I made such a trigger:
  • Trigger
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
      • (Life of (Kael1)) Less than or equal to 50.00
      • (Life of (Kael2)) Less than or equal to 50.00
    • Actions
      • Set Point = (Center of (Destination_Region1))
      • Unit - Move (Kael1) instantly to Point
      • Custom script: call RemoveLocation (udg_Point)
      • Set Point = (Center of (Destination_Region2))
      • Unit - Move (Kael2) instantly to Point
      • Custom script: call RemoveLocation (udg_Point)
      • Trigger - Turn off (This trigger)
The only variable I use is point-Point.
This checks every 0.1 if Kaels have enaugh life to be teleported.
But you may use variables for kaels then replace Kaels in Conditions and actions with those variables.
 
Level 5
Joined
Aug 6, 2009
Messages
136
Ok.Its kinda important then >.<

Cause when i save the map with the Custom Script i get Error.

So any solutions? :s
 
Level 7
Joined
Oct 26, 2005
Messages
190
Just a complementary information about the point: If that point is going to be static, isn't it better to store it at map start? That way there's no need to neither store the variable everytime nor remove the leak...
 
Level 18
Joined
Feb 28, 2009
Messages
1,971
Just a complementary information about the point: If that point is going to be static, isn't it better to store it at map start? That way there's no need to neither store the variable everytime nor remove the leak...
Ofc you can, but I get used to use only one Point variable for everything.
 
Level 13
Joined
Sep 14, 2008
Messages
1,408
See it works like this:

When you referre to a location in wc3 the location (most likely as coordinates) is saved in the PC-Memory.
Normal programming languages like JAVA automaticly removes stored values from the memory but wc3 does not.

So when you perodicly use a lot of locations they all stay in the memory without being removed. That results in a critical error when the wc3 ram limit is reached.

If you don't want to get the error you save the location to a variable (so you can address it later) and after using it remove the stored value from the memory.
(the custom script is doing that)
 
Level 5
Joined
Aug 6, 2009
Messages
136
So . . . If i keep making lots of those: as an example: Units enters region / move unit instantly to [region]
i will get an error? :eek:
 
Level 7
Joined
Oct 26, 2005
Messages
190
Not really, it will cause the game to lag at some moment, it's very easy to store a point in a variable and remove it later once you get the hang of it.

For the point example, you first create a Point variable called (for example: TempPoint), look in Actions -> Set Variable. You set TempPoint = Center of (Region)/Position of (unit)/etc.... anything you want
Then you use the actions that will, instead of using Center of (Region)/Position of (unit)/etc, you use the variable we stored.
Finally after you think the variable point made its work, you use Custom script and write: call RemoveLocation (udg_TempPoint) <--- Remember to write the name of the variable exactly as you called it, instead of TempPoint
 
Level 5
Joined
Aug 6, 2009
Messages
136
So it will be something like this:

Event: Unit enters [ Region ]
condition:
Action: Set variable [Name of variable] ( region thingy)

Instead of: Move unit instantly?
 
Level 5
Joined
Aug 6, 2009
Messages
136
Ohh i meant like that xD

Like first you store a region in the variable.

Then set up variable. But dont i have to make lots of stored regions then?
 
Level 9
Joined
Oct 2, 2008
Messages
406
I didn't know that regions leak?
Do they?

Lets say you have trigger that makes Footman go to the center of a region.

First you store center of region in variabe (lets call variable CenterRegionVar)

Set CenterRegionVar = Center of Your Region (place where footman goes)

Then goes the action that makes footman go there

Make unit Footman go to CenterRegionVar ( you have to use variable where you put real point)

Then, you empty the variable with custom script, because there is no GUI command for that.

call RemoveLocation(udg_CenterRegionVar)

And thats it. Each time before you use location you store it inside the variable and after use you clean it up.
Hope I helped.
 
Preset regions (through the Editor) do not leak. Regions created in-game by this function, do leak:
  • Set Point1 = (Position of (Triggering unit))
  • Set Region1 = (Region centered at Point1 with radius (300.00, 300.00) //This is a region-type variable.
  • Custom script: call RemoveLocation (udg_Point1)
To remove that leak, simply make the call
  • Custom script: call RemoveRect (udg_Region1)
 
Level 13
Joined
Feb 18, 2009
Messages
1,381
First of all. Use "Triggering unit" instead of "Entering unit" and, it wont look any else like the normal moving, it is just more smooths, and it is leakless.
 
Level 5
Joined
Aug 6, 2009
Messages
136
Event:
Unit - A unit enters [Region] <gen>

Condition:

Action:
Set Teleportation = (Center of Region 109 <gen>)
Unit - Move Kael 0119 <gen> instantly to Teleportation
Custom script: call RemoveLocation (udg_Teleportation)

Is that right?
 
Level 5
Joined
Aug 6, 2009
Messages
136
Event:
Unit - A unit enters [Region] <gen>

Condition:

Action:
Set Teleportation = (Center of Region 109 <gen>)
Unit - Move Triggering unit <gen> instantly to Teleportation
Custom script: call RemoveLocation (udg_Teleportation)

That should do the trick.
 
Level 15
Joined
Aug 14, 2007
Messages
936
OK just to make sure you understand why we need to clean the point variable

When u use for example: Position of Unit
Warcraft will store Position of unit as A Variable they name automatically (pt001 for example)

Imagine u create 100 units with Position of Unit
Then warcraft will store the points as pt001 to pt100
so.. 101th ran will be pt101
cuz the variable last forever until game ends

So now, we catch the Position of Unit in the variable
Set ClearPoint = Position of Unit
Use ClearPoint
call RemoveLocation(ClearPoint)
warcraft won't auto create for you since u already refered it as a variable!
 
Level 5
Joined
Aug 6, 2009
Messages
136
So it isn't like ''Ohh right so i can use the variable replacing the Move unit instantly to [region] action! '' what i said earlier? :s
 
Level 5
Joined
Aug 6, 2009
Messages
136
cause i believe it is :p

Another request ( question ).

Is it hard to make the spells deal x int ( agi / str ) u have?

If anyone has a tutorial,link that shows how i would be thankful :eek:
 
Level 18
Joined
Feb 28, 2009
Messages
1,971
You can do this only for triggered spells.
  • Actions
    • Set damage = (Strength of (Triggering unit) (Include bonuses)) --- This is integer variable
    • Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (Real(damage)) damage of attack type Spells and damage type Normal
(Real(damage)) --- is a conversion (integer to real)
 
Level 5
Joined
Aug 6, 2009
Messages
136
i know lol. But if not using triggered spells. Cant u do like:

When unit casts a spell add x damage to the spell. By x int u have?
 
Level 5
Joined
Aug 6, 2009
Messages
136
If im going to do like the following:

When 2 units dies [ After they both died ]

Open gate.

Not only when one dies. But when 2 guys dies. Then open door.

Any clues?
 
Level 5
Joined
Aug 6, 2009
Messages
136
  • Trigger
  • Events
    • Unit - A unit dies
  • Conditions
  • Actions
    • If (All conditions are true) then do (Actions) else do (Actions)
      • If - Conditions
        • (Count) Not Equal to 2
      • Then - Actions
        • Set Count = (Count + 1)
      • Else - Actions
        • Destructible - Open (gate)
        • Set Count = 0
Count is an integer variable.


Wait,where's is the dying unit?
 
Status
Not open for further replies.
Top