| 06-03-2005, 06:47 PM | #1 |
I want to make a loop that exits when a player reaches or goes over their maxium amount of food. So, I looked, and couldn't see a way to do it in the GUI, because the only loops are for int a... >< I researched a little and this is as far as I can get loop if unit enters and owner = player[1] region then exitwhen i>=max food for player[1] set i=current food for player[1] Create unit[type of entering unit for player[1] at region[1] endif endloop BTW, what I am trying to do is make it so when a unit enters a certain region, the a unit of the same unit type of entering unit, spawns in another region, over and over, 1 by 1, until the food limit for the owner of those units is reached. But Im really not sure how to go about it, any help is appreciated. |
| 06-03-2005, 09:13 PM | #2 |
Try to convert it to jass and post it here |
| 06-04-2005, 02:19 AM | #3 |
Guest | Well I always make long ways to go about things but try this...note: I do not have WE open... First trigger: (make sure this trigger if initally off) Code:
Spawn unit E:Time - Every 2 seconds of game time A:Unit - Create 1 Footman Code:
Trigger spawn E:Unit - Unit enters <region> A:Trigger - Turn on "Spawn unit" Code:
E:Player 1's food equal to/greater than 100/100 (greater than just incase) A: Turn off "Spawn Unit" Yeh...long way..at least it's something =\ |
| 06-04-2005, 06:11 AM | #4 |
Code:
periodic every 2 seconds pick every unit in (units in regionX) ++if owner of picked unit's food is less than owner of picked units max food then ++++create 1 (unit type of (picked unit)) at regionY for owner of picked unit just a sample to start you off, if you choose to use it, it will duplicate all units as well, if there are 3 units in the area it will dupe all 3, also it doesn't take care of memory leaks but that should start you off |
| 06-04-2005, 03:26 PM | #5 |
unit enter [Reigon] foreach integer a/b from 1 to (players food limit) do if ( player(#) food is < (players food limit)) then spawn 1 (unit) for (player) at (reigon) else do nothing end loop i dont have the WE open, so this may be a little confusing. (and im lazy) |
| 06-04-2005, 04:47 PM | #6 |
Raptor--'s solution is nice and efficient, go with it. |
| 06-04-2005, 05:37 PM | #7 | |
Quote:
Yeah, that's what I am currently using as my spawn trigger, but I thought maybe I could use this so learn a little JASS or somthing, can you not do loops like that in JASS? Or...? |
| 06-04-2005, 05:49 PM | #8 |
Loops are more efficient in JASS. I learned JASS with this, but already having a programming background helps too. http://jass.sourceforge.net/doc/ |
| 06-04-2005, 08:30 PM | #9 |
And here is a great begginer's guide to JASS made by Lord Vexorian. |
| 06-05-2005, 12:59 AM | #10 |
createing a tirgger that doas what you want and converting it to JASS is a nice way to learn JASS as well. (if you learn better by example, like me :) i taut myself PHP, Javascript, and JASS by reading code! no tutorials at all :) (sept for JASS)) anywho, JASS is nice, but if you just dont understand it, stick to GUI. The GUI is nice for people who arnt good at programing. (or lazy, like me) |
| 06-05-2005, 04:13 AM | #11 |
Well, anyway, this is what I came up with for the JASS, and it works. But...it creates all the units at once, maybe if I add a wait for somthing, and Raptor said somthing about memory leaks? Does me doing it in JASS change anything? Or do I need to add some line, if so what? Code:
function Trig_Spawn_Conditions takes nothing returns boolean
if ( not ( GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
return false
endif
return true
endfunction
function Trig_Spawn_Actions takes nothing returns nothing
loop
exitwhen GetPlayerState(Player(0), PLAYER_STATE_RESOURCE_FOOD_USED) >= GetPlayerState(Player(0), PLAYER_STATE_FOOD_CAP_CEILING)
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
call TriggerSleepAction( 1.00 )
endloop
endfunction
//===========================================================================
function InitTrig_Spawn takes nothing returns nothing
set gg_trg_Spawn = CreateTrigger( )
call TriggerRegisterEnterRectSimple( gg_trg_Spawn, gg_rct_P1Spawn )
call TriggerAddCondition( gg_trg_Spawn, Condition( function Trig_Spawn_Conditions ) )
call TriggerAddAction( gg_trg_Spawn, function Trig_Spawn_Actions )
endfunctionEDIT: Ok, adding the wait works great! But now, I want to add another exit, which Im not sure if it's possible to have 2 exitwhen lines, but I hope it is...What I want the next one to do is exit if the unit leaves P1Spawn...so how would that look? I tried Code:
exitwhen CountUnitsInGroup(GetUnitsInRectAll(gg_rct_P1Spawn)) == 0 |
| 06-05-2005, 09:18 AM | #12 |
You may be encountering a unit enters region event problem where the unit is not always in the region when it enters it. I wrote more about all that here. I think you could solve this problem by putting a small wait before the loop, thus allowing the unit to really be in the region before checking for the number of units in region. As far as memory leaks go, you should check some tutorials about it in the tutorials section, after that you can find some usefull information in this thread as well. |
| 06-05-2005, 04:20 PM | #13 | |
Quote:
that's crazy, the wait thing worked Blizz should really fix that tho...as for the memory leaks, my JASS knowledge seems to be lacking, making me not being able to understand what you guys said in that thread =P |
| 06-05-2005, 04:55 PM | #14 | |
Quote:
|
| 06-06-2005, 01:12 AM | #15 |
Hmm...ok, so I need to set all of the created units in a unit group, then make a trigger that when a unit dies, checks to see if it is in that group (lol 4 2 letter words in a row) and then do the remove trigger? |
