And syntax

Started by wolkiewicz, July 16, 2015, 11:47:51 AM

Previous topic - Next topic

wolkiewicz

Hello there!
I am writing a code, and i used "and" first time and it doesn't work. Can somene help me fix that? Unit works fine with it but it doesn't make sound. Also, another question: is there an effect that looks like red light?

There's the code:
once
SetTimer2(1800)
endonce

if(GetTimer2 900 gt)
PlaySound("Misc 1")
30 Delay
endif

GetTimer2 350 gt and
GetTimer2 900 lte and
if
PlaySound("Misc 1")
15 Delay
endif

GetTimer2 350 lte and
GetTimer2 neq0 and
if
PlaySound("Misc 1")
7 Delay
endif

if(GetTimer2 eq0)
PlaySound("Weapons 27")
GetUnitAttribute(Self CONST_AMMOAC) ->ammo
<-payload <-ammo sub ->payload
CurrentCoords <-payload AddCreeper
Destroy(Self 0)
endif


:awake
once
SetUnitAttribute(Self CONST_CONNECTABLE TRUE)
SetUnitAttribute(Self CONST_REQUESTACPACKETS TRUE)
SetUnitAttribute(Self CONST_MAXAMMOAC <-payload 2 mul)
SetUnitAttribute(self CONST_CREATEPZ FALSE)
SetUnitAttribute(self CONST_TAKEMAPSPACE FALSE)
SetUnitAttribute(Self CONST_SUPPORTSDIGITALIS FALSE)
SetUnitAttribute(Self CONST_NULLIFIERDAMAGES FALSE)
SetUnitAttribute(Self CONST_COUNTSFORVICTORY FALSE)
endonce


3rd question- are timers set to a script or to a map?

Karsten75

Your syntax is all messed up. You have Warp notation, but no brackets on the "and"

Timers are game-related - thus per map.

wolkiewicz

There aren't good examples at the wiki and i dunno how to use it. Can you explain me how should it look like?

Tyler21

#3
First, I suggest to use either the stack notation or the warp notation. You can easily get lost in the code if you use both. Stack notation requires a bit different thinking than usual programming, but you can get used to it after a while.

Second, if you have two arguments and you want to implement a boolean operation, you have to include the operator only once.
For instance this is how the code looks like with stack notation:

GetTimer2 350 gt
GetTimer2 900 lte and
if
...
endif


Note that there is no "and" after the first argument. The "and" function takes the last two elements from the stack and if both are "TRUE", it puts a "TRUE" on the top of the stack. Otherwise, it puts a "FALSE" on top.
In your original code the first "and" checked the "GetTimer2 350 gt" argument and the second to last item on the stack (the stack was empty at that point so this item was null). So the result of the boolean was FALSE that's why the code didn't work.

"Enjoyment appears at the boundary between boredom and anxiety, when the challenges are just balanced with the person's capacity to act."
― Mihaly Csikszentmihalyi

Check my collection of the 30 most difficult and challenging maps in Colonial Space!

warren

I would like to point out that timers are instance bound -- there exists a one to one relationship between timers and script instances, there could be many timers to one script, and many timers to one map -- therefore:
  If you create a core with script a; then ten seconds later create a core with script a; the time will go off once on the first core, then ten seconds later on the second core.
  Nothing you do on one map will affect another map, including timer related stuff (notable exception being the keys).

Most of the effects are just explosions. If you want something special, you can make it with a script.

Asbestos

http://knucklecracker.com/wiki/doku.php?id=crpl:crpltutorial:code_examples#alpha_blink
Make an image of a red circle, put it on a core, and put this script in the core. That will create a blinking red light. If you want just a constant red light, make the image slightly transparent, then don't put any scripts on it.