Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Clean0nion on October 30, 2013, 07:08:13 PM

Title: A command to repeat something a set number of times?
Post by: Clean0nion on October 30, 2013, 07:08:13 PM
Sorry to have to ask another probably stupid question but how can I get something to repeat a number of times?

UPDATE: I worked it out. Ignore me.

For those who would ask because they are equally stupid as I, I used the Do and Loop command.

UPDATE: Turns out I haven't worked it out. My brain is currently dying.
Title: Re: A command to repeat something a set number of times?
Post by: eduran on October 30, 2013, 07:41:18 PM

$payload:10
$sporeHealth:10

if (<-fire)
@GetUnitTypeCount("REACTOR") ->reactorCount     
do(reactorCount 0)
# add code to select target coordinates
CreateSpore(CurrentCoords <-targetX <-targetY <-sporeHealth <-payload)
loop
endif

:GetUnitTypeCount
->unitType
0 ->count
do (GetUnitCountInRange(0 0 9999) 0)
->unitUID
if (GetUnitType(<-unitUID) eq(<-unitType))
<-count add(1) ->count
endif
loop
<-count


This should do the trick.
Title: Re: A command to repeat something a set number of times?
Post by: Clean0nion on October 30, 2013, 07:55:32 PM
Quote from: eduran on October 30, 2013, 07:41:18 PM

bunch of code


This should do the trick.

What you've done looks good but still doesn't work. I think my issues are in the "if (<-fire)" line. fire is probably the criteria for launching spores that I haven't set yet. I'll sort that out now. Thanks for lending a hand.

UPDATE: I now have this.
$payload:10
$sporeHealth:10

if ((<-fire) eq(1))
@GetUnitTypeCount("REACTOR") ->reactorCount     
do(<-reactorCount 0)
CreateSpore(CurrentCoords RandUnitCoords <-sporeHealth <-payload)
loop
0 ->fire
endif

90 delay
1 ->fire

:GetUnitTypeCount
->unitType
0 ->count
do (GetUnitCountInRange(0 0 9999) 0)
->unitUID
if (GetUnitType(<-unitUID) eq(<-unitType))
<-count add(1) ->count
endif
loop
<-count

Doesn't work. I have no idea what's going on anymore.
Title: Re: A command to repeat something a set number of times?
Post by: Lost in Nowhere on October 30, 2013, 09:01:06 PM
Quote from: Clean0nion on October 30, 2013, 07:55:32 PM
Quote from: eduran on October 30, 2013, 07:41:18 PM

bunch of code


This should do the trick.

What you've done looks good but still doesn't work. I think my issues are in the "if (<-fire)" line. fire is probably the criteria for launching spores that I haven't set yet. I'll sort that out now. Thanks for lending a hand.

UPDATE: I now have this.
-snip-
Doesn't work. I have no idea what's going on anymore.
Try this:
$payload:10
$sporeHealth:10

@GetUnitTypeCount("REACTOR") ->reactorCount     
do(<-reactorCount dup mul 0)
CreateSpore(CurrentCoords RandUnitCoords <-sporeHealth <-payload)
loop

90 delay

:GetUnitTypeCount
->unitType
0 ->count
do (GetUnitCountInRange(0 0 9999) 0)
->unitUID
if (GetUnitType(<-unitUID) eq(<-unitType))
<-count add(1) ->count
endif
loop
<-count

It also uses the square of the number of reactors. You probably will want to increase the 90-frame delay (3 seconds), though.
Title: Re: A command to repeat something a set number of times?
Post by: Grayzzur on October 30, 2013, 10:19:37 PM
Delay makes your entire CRPL Core pause at that spot until the delay time is up. If it's doing other things besides just firing those spores, you may want to use a timer instead of a delay.

$InitialDelay:3600
$WaveInterval:900

once
SetTimer0 (<-InitialDelay) # Sets up the initial delay
endonce

if (eq0(GetTimer0)) # do this only when the timer hits zero
# Fire your spores here

SetTimer0 (<-WaveInterval) # reset the timer for the next interval
endif

# Do other stuff
Title: Re: A command to repeat something a set number of times?
Post by: Clean0nion on November 01, 2013, 07:07:57 AM
Quote from: Grayzzur on October 30, 2013, 10:19:37 PM
Delay makes your entire CRPL Core pause at that spot until the delay time is up. If it's doing other things besides just firing those spores, you may want to use a timer instead of a delay.

$InitialDelay:3600
$WaveInterval:900

once
SetTimer0 (<-InitialDelay) # Sets up the initial delay
endonce

if (eq0(GetTimer0)) # do this only when the timer hits zero
# Fire your spores here

SetTimer0 (<-WaveInterval) # reset the timer for the next interval
endif

# Do other stuff

Thanks. I'll test this out later.