wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-31-2010, 06:43 PM   #1
rednek
",:..:,"
 
rednek's Avatar
 
Join Date: May 2006
Posts: 236

Submissions (11)

rednek will become famous soon enough (61)rednek will become famous soon enough (61)rednek will become famous soon enough (61)

Default Find minimal value?

Let we say I have 10 integer variables, each of them has random number between 0 and 100.
Now, how can I find which one of them has lowest value? Min function World Editor has can compare only two variables (as far as I know)

Or

I'm doing this, because I'm trying to find closest unit to a certain point. If there's any clear way to find which one is it, well, I'm all ears :)
__________________
.

(lol, a hole in there, damn I fail :C )
rednek is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-31-2010, 06:49 PM   #2
Kueken
User
 
Join Date: Mar 2009
Posts: 149

Kueken will become famous soon enough (41)Kueken will become famous soon enough (41)

Default

For the first one, use a sort algorithm, or simply loop though the numbers and get the lowest one by multiple comparisons

For the second one, pick all units and compare their distances like mentioned
Kueken is offline   Reply With Quote
Old 01-31-2010, 07:24 PM   #3
rednek
",:..:,"
 
rednek's Avatar
 
Join Date: May 2006
Posts: 236

Submissions (11)

rednek will become famous soon enough (61)rednek will become famous soon enough (61)rednek will become famous soon enough (61)

Default

Thanks for the reply, could you be more specific please?

The number of variables is unknown to me, might be more than 10. I can't imagine how to sucesfully compare them, without having it to be ridiculously long.
What is this sorting algoritm you speak of, and how do I accomplish it?
__________________
.

(lol, a hole in there, damn I fail :C )

Last edited by rednek : 01-31-2010 at 07:24 PM.
rednek is offline   Reply With Quote
Old 01-31-2010, 07:48 PM   #4
TriggerHappy
 
Join Date: Feb 2008
Posts: 405

Submissions (2)

TriggerHappy will become famous soon enough (43)TriggerHappy will become famous soon enough (43)

Default

Should output the lowest #. Not tested (or syntax checked).

Collapse JASS:
local integer i = 1
local integer lowest = yourArray[0]
local integer index  = 0
loop
    exitwhen i > 10
    if (yourArray[i] < lowest) then
        set lowest = yourArray[i]
        set index  = i
    endif
    set i = i + 1
endloop
call BJDebugMsg("yourArray["+I2S(index)+"] has the lowest value, " + I2S(lowest))
TriggerHappy is offline   Reply With Quote
Old 01-31-2010, 07:53 PM   #5
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Collapse JASS:
globals
   integer array A
   integer Size = 9 // for values in the array with index between 0 - 9
endglobals

function Min10 takes nothing returns integer
   local integer i = 0
   local integer r = A[0]
   local integer a = 0
   loop
      exitwhen i == Size
      set a = Min(A[i], A[i+1])
      if a < r then
         set r = a
      endif
      set i = i+1
   endloop
   return r
endfunction
moyack is offline   Reply With Quote
Old 01-31-2010, 07:56 PM   #6
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

If you want to find the nearest unit to a point, PruneGroup can help.
__________________
Anitarf is offline   Reply With Quote
Old 01-31-2010, 08:04 PM   #7
Michael Peppers
Lepus?
 
Michael Peppers's Avatar
 
Join Date: Jan 2009
Posts: 1,308

Michael Peppers is a jewel in the rough (188)Michael Peppers is a jewel in the rough (188)Michael Peppers is a jewel in the rough (188)

Default

Quote:
Originally Posted by Anitarf
If you want to find the nearest unit to a point, PruneGroup can help.
...or my FindUnits =P
__________________
Projects:Tutorials: Competitive AI Step by Step with AI Editor (Pending)
Resources: [AI Script] Michael Peppers's Melee AI template (Pending)

Last edited by Michael Peppers : 01-31-2010 at 08:04 PM.
Michael Peppers is offline   Reply With Quote
Old 01-31-2010, 08:53 PM   #8
Themerion
Brahms-fan
 
Themerion's Avatar
 
Join Date: Jan 2006
Posts: 642

Submissions (2)

Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)

Default

Quote:
I'm trying to find closest unit to a certain point.

Here's an outline for how it's done. It's made to be simple, read comment on (meaningless? :P) optimizations below.

Trigger:
Set CertainPoint = (Center of (Playable Map Area))
Set TempReal = 500
Set TempUnit = No Unit
Collapse Unit Group - Pick All units in 500 from CertainPoint
Collapse Loop
Collapse If
Collapse Conditions
Distance Between (Certain Point) and (Position of (Picked Unit)) less than TempReal
Collapse Actions
Set TempUnit = (Picked Unit)
Set TempReal = Distance Between (Certain Point) and (Position of (Picked Unit))

Collapse if TempUnit not equal to No Unit
--- Voila, the closest unit was TempUnit ---

Once you understand this outline, you should probably optimize it by storing "Distance Between..." as a variable (so you won't have to check multiple times for the same unit). You should also take care of the point-leaks, and the unit group leak.
__________________
Submissions::
(v)JASS Tutorial
Covers how to make fast and safe coding for common tasks in vJASS/JASS.
Creep Respawn System
It has never been easier to respawn creep groups...

Last edited by Themerion : 01-31-2010 at 09:00 PM.
Themerion is offline   Reply With Quote
Old 01-31-2010, 11:06 PM   #9
rednek
",:..:,"
 
rednek's Avatar
 
Join Date: May 2006
Posts: 236

Submissions (11)

rednek will become famous soon enough (61)rednek will become famous soon enough (61)rednek will become famous soon enough (61)

Default

Whoa, thanks for all the replies, I went with the moyack's one for finding lowest value, and it works perfectly (thanks man)
After that, Themerion's trigger was clear as day to me. I'm glad you posted it :P
So, yeah, thanks again ^^
__________________
.

(lol, a hole in there, damn I fail :C )

Last edited by rednek : 01-31-2010 at 11:10 PM.
rednek is offline   Reply With Quote
Old 02-01-2010, 02:06 PM   #10
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by rednek
Whoa, thanks for all the replies, I went with the moyack's one for finding lowest value, and it works perfectly
It does? It doesn't even compile for me.
__________________
Anitarf is offline   Reply With Quote
Old 02-01-2010, 02:37 PM   #11
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Anitarf
It does? It doesn't even compile for me.
Man, you suck at coding.... :P
moyack is offline   Reply With Quote
Old 02-01-2010, 06:05 PM   #12
rednek
",:..:,"
 
rednek's Avatar
 
Join Date: May 2006
Posts: 236

Submissions (11)

rednek will become famous soon enough (61)rednek will become famous soon enough (61)rednek will become famous soon enough (61)

Default

Quote:
Originally Posted by Anitarf
It does? It doesn't even compile for me.

Perhaps, I didn't exactly copy'n'paste it, just saw how it's done and then did it by memory.
__________________
.

(lol, a hole in there, damn I fail :C )
rednek is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 05:00 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services