HELP!The script doesn't run as it designed.

Started by glease, June 30, 2014, 09:32:09 AM

Previous topic - Next topic

glease

My idea is a SporeTower launch AC spores and it will require energy/AC to function.But it always launches regardless of the ammo/AC amt.The popup text sometimes goes wrong,too.why?


#If 0,the tower will require 30 packets to build.
$IsBuilt:1
$Interval:30
$PayLoad:10
#If any vars below is lte 0,the tower won't require Energy/AC.
$RequiredEnergy:0.5
$RequiredAC:0.0


once
#Make popup text.
"
" ->Crlf
if ( <-IsBuilt 1 neq )
Self CONST_ISBUILDING 1 SetUnitAttribute
Self CONST_BUILDCOST 30 SetUnitAttribute
endif
"Interval:" <-Interval concat <-Crlf concat "AC PayLoad:" <-PayLoad concat concat ->PopupText
if ( <-RequiredEnergy 0 gt )
<-PopupText <-Crlf concat "RequiredEnergy:" concat <-RequiredEnergy concat
1 ->RequireEnergy
SetUnitAttribute ( Self CONST_REQUESTPACKETS 1 )
Trace ( "1" )
else
0 ->RequireEnergy
SetUnitAttribute ( Self CONST_REQUESTPACKETS 0 )
Trace ( "2" )
endif
if ( <-RequiredAC 0 gt )
<-PopupText <-Crlf concat "RequiredAC:" concat <-RequiredAC concat
1 ->RequireAC
SetUnitAttribute ( Self CONST_REQUESTACPACKETS 1 )
Trace ( "3" )
else
0 ->RequireAC
SetUnitAttribute ( Self CONST_REQUESTACPACKETS 0 )
Trace ( "4" )
endif
SetPopupText ( <-PopupText )
ShowTraceLog
ClearStack
endonce


if ( <-RequireAC and ( GetUnitAttribute ( Self CONST_AMMOAC )  gte ( <-RequiredAC )  )  and ( <-RequireEnergy and ( GetUnitAttribute ( Self CONST_AMMO )  gte ( <-RequiredEnergy )  )  )  not GetTimer0 eq0 and )
Trace ( "5" )
if ( <-RequireEnergy )
SetUnitAttribute ( Self CONST_AMMO GetUnitAttribute ( Self CONST_AMMO )  <-RequiredEnergy sub )
Trace ( "6" )
endif
if ( <-RequireAC )
SetUnitAttribute ( Self CONST_AMMOAC GetUnitAttribute ( Self CONST_AMMOAC )  <-RequiredAC sub )
Trace ( "7" )
endif
CurrentCoords RandCoords 1 <-PayLoad -1 mul CreateSpore
SetTimer0 ( <-Interval )
Trace ( "8" )
endif

Trace ( GetUnitAttribute ( Self CONST_AMMO )  )
ClearStack


p.s:does someone have a picture of the spore tower?i will give create to him when my map published.

Grayzzur

Your big IF statement, which was a bit hard to read at first, basically says:

If NOT (requires energy and has enough energy and requires ac and has enough ac) and Timer0=0
So, ironically, having enough energy and AC and requiring both is the one condition that will cause it to NOT fire.

You need to aim for something like

If (NOT require energy OR has enough energy) and (NOT require AC OR has enough AC) and Timer0=0

As for the popup text, in your two IF statements inside the ONCE block where you are trying to append extra information to it, you forgot to save the results back to the variable with "->PopupText" at the end of those lines.

As a side note, you don't need the ClearStack at the bottom of your code. CRPL does not save the stack between game frames.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

ParkourPenguin

Grayzurr is correct. Change it to something more like:
if ( <-RequireAC not or ( GetUnitAttribute ( Self CONST_AMMOAC )  gte ( <-RequiredAC )  )  and ( <-RequireEnergy not or ( GetUnitAttribute ( Self CONST_AMMO )  gte ( <-RequiredEnergy )  )  )   GetTimer0 eq0 and )

Also, if you're looking for an image of the spore tower, there's one on the wiki located at http://knucklecracker.com/wiki/doku.php?id=cw3:units:enemy.
"Only a life lived for others is a life worthwhile."
-Albert Einstein