Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Annonymus on November 28, 2013, 01:17:12 PM

Title: CRPL script isn't working
Post by: Annonymus on November 28, 2013, 01:17:12 PM
I am making a script that should simulate a basic calculator and it works until I have to display the numbers, at the point where i try to modify the terrain it just doesn't do anyhing  :'(

Here's the script (currently 476 lines of code so it's ok if you don't want to help me because it's too much to read):

# calculator.crpl
# Created on: 11/28/2013 4:28:53 PM
# ------------------------------------------
$1x:11
$1y:13
$2x:20
$2y:13
$3x:29
$3y:13
$4x:11
$4y:22
$5x:20
$5y:22
$6x:29
$6y:22
$7x:11
$7y:31
$8x:20
$8y:31
$9x:29
$9y:31
$plusx:41
$plusy:18
$minusx:51
$minusy:18
$multiplyx:51
$multiplyy:28
$dividex:41
$dividey:28
$resultx:57
$resulty:20
$resultterrain:10

#creates the collectors and sets terrain under them to 10
once
"collector" <-1x <-1y CreateUnit
<-1x <-1y 10 SetTerrain
<-1x <-1y 1 add 10 SetTerrain
<-1x <-1y 1 sub 10 SetTerrain
<-1x 1 add <-1y 10 SetTerrain
<-1x 1 add <-1y 1 add 10 SetTerrain
<-1x 1 add <-1y 1 sub 10 SetTerrain
<-1x 1 sub <-1y 10 SetTerrain
<-1x 1 sub <-1y 1 add 10 SetTerrain
<-1x 1 sub <-1y 1 sub 10 SetTerrain

"collector" <-2x <-2y CreateUnit
<-2x <-2y 10 SetTerrain
<-2x <-2y 1 add 10 SetTerrain
<-2x <-2y 1 sub 10 SetTerrain
<-2x 1 add <-2y 10 SetTerrain
<-2x 1 add <-2y 1 add 10 SetTerrain
<-2x 1 add <-2y 1 sub 10 SetTerrain
<-2x 1 sub <-2y 10 SetTerrain
<-2x 1 sub <-2y 1 add 10 SetTerrain
<-2x 1 sub <-2y 1 sub 10 SetTerrain

"collector" <-3x <-3y CreateUnit
<-3x <-3y 10 SetTerrain
<-3x <-3y 1 add 10 SetTerrain
<-3x <-3y 1 sub 10 SetTerrain
<-3x 1 add <-3y 10 SetTerrain
<-3x 1 add <-3y 1 add 10 SetTerrain
<-3x 1 add <-3y 1 sub 10 SetTerrain
<-3x 1 sub <-3y 10 SetTerrain
<-3x 1 sub <-3y 1 add 10 SetTerrain
<-3x 1 sub <-3y 1 sub 10 SetTerrain

"collector" <-4x <-4y CreateUnit
<-4x <-4y 10 SetTerrain
<-4x <-4y 1 add 10 SetTerrain
<-4x <-4y 1 sub 10 SetTerrain
<-4x 1 add <-4y 10 SetTerrain
<-4x 1 add <-4y 1 add 10 SetTerrain
<-4x 1 add <-4y 1 sub 10 SetTerrain
<-4x 1 sub <-4y 10 SetTerrain
<-4x 1 sub <-4y 1 add 10 SetTerrain
<-4x 1 sub <-4y 1 sub 10 SetTerrain

"collector" <-5x <-5y CreateUnit
<-5x <-5y 10 SetTerrain
<-5x <-5y 1 add 10 SetTerrain
<-5x <-5y 1 sub 10 SetTerrain
<-5x 1 add <-5y 10 SetTerrain
<-5x 1 add <-5y 1 add 10 SetTerrain
<-5x 1 add <-5y 1 sub 10 SetTerrain
<-5x 1 sub <-5y 10 SetTerrain
<-5x 1 sub <-5y 1 add 10 SetTerrain
<-5x 1 sub <-5y 1 sub 10 SetTerrain

"collector" <-6x <-6y CreateUnit
<-6x <-6y 10 SetTerrain
<-6x <-6y 1 add 10 SetTerrain
<-6x <-6y 1 sub 10 SetTerrain
<-6x 1 add <-6y 10 SetTerrain
<-6x 1 add <-6y 1 add 10 SetTerrain
<-6x 1 add <-6y 1 sub 10 SetTerrain
<-6x 1 sub <-6y 10 SetTerrain
<-6x 1 sub <-6y 1 add 10 SetTerrain
<-6x 1 sub <-6y 1 sub 10 SetTerrain

"collector" <-7x <-7y CreateUnit
<-7x <-7y 10 SetTerrain
<-7x <-7y 1 add 10 SetTerrain
<-7x <-7y 1 sub 10 SetTerrain
<-7x 1 add <-7y 10 SetTerrain
<-7x 1 add <-7y 1 add 10 SetTerrain
<-7x 1 add <-7y 1 sub 10 SetTerrain
<-7x 1 sub <-7y 10 SetTerrain
<-7x 1 sub <-7y 1 add 10 SetTerrain
<-7x 1 sub <-7y 1 sub 10 SetTerrain

"collector" <-8x <-8y CreateUnit
<-8x <-8y 10 SetTerrain
<-8x <-8y 1 add 10 SetTerrain
<-8x <-8y 1 sub 10 SetTerrain
<-8x 1 add <-8y 10 SetTerrain
<-8x 1 add <-8y 1 add 10 SetTerrain
<-8x 1 add <-8y 1 sub 10 SetTerrain
<-8x 1 sub <-8y 10 SetTerrain
<-8x 1 sub <-8y 1 add 10 SetTerrain
<-8x 1 sub <-8y 1 sub 10 SetTerrain

"collector" <-9x <-9y CreateUnit
<-9x <-9y 10 SetTerrain
<-9x <-9y 1 add 10 SetTerrain
<-9x <-9y 1 sub 10 SetTerrain
<-9x 1 add <-9y 10 SetTerrain
<-9x 1 add <-9y 1 add 10 SetTerrain
<-9x 1 add <-9y 1 sub 10 SetTerrain
<-9x 1 sub <-9y 10 SetTerrain
<-9x 1 sub <-9y 1 add 10 SetTerrain
<-9x 1 sub <-9y 1 sub 10 SetTerrain

"collector" <-plusx <-plusy CreateUnit
<-plusx <-plusy 10 SetTerrain
<-plusx <-plusy 1 add 10 SetTerrain
<-plusx <-plusy 1 sub 10 SetTerrain
<-plusx 1 add <-plusy 10 SetTerrain
<-plusx 1 add <-plusy 1 add 10 SetTerrain
<-plusx 1 add <-plusy 1 sub 10 SetTerrain
<-plusx 1 sub <-plusy 10 SetTerrain
<-plusx 1 sub <-plusy 1 add 10 SetTerrain
<-plusx 1 sub <-plusy 1 sub 10 SetTerrain

"collector" <-minusx <-minusy CreateUnit
<-minusx <-minusy 10 SetTerrain
<-minusx <-minusy 1 add 10 SetTerrain
<-minusx <-minusy 1 sub 10 SetTerrain
<-minusx 1 add <-minusy 10 SetTerrain
<-minusx 1 add <-minusy 1 add 10 SetTerrain
<-minusx 1 add <-minusy 1 sub 10 SetTerrain
<-minusx 1 sub <-minusy 10 SetTerrain
<-minusx 1 sub <-minusy 1 add 10 SetTerrain
<-minusx 1 sub <-minusy 1 sub 10 SetTerrain

"collector" <-multiplyx <-multiplyy CreateUnit
<-multiplyx <-multiplyy 10 SetTerrain
<-multiplyx <-multiplyy 1 add 10 SetTerrain
<-multiplyx <-multiplyy 1 sub 10 SetTerrain
<-multiplyx 1 add <-multiplyy 10 SetTerrain
<-multiplyx 1 add <-multiplyy 1 add 10 SetTerrain
<-multiplyx 1 add <-multiplyy 1 sub 10 SetTerrain
<-multiplyx 1 sub <-multiplyy 10 SetTerrain
<-multiplyx 1 sub <-multiplyy 1 add 10 SetTerrain
<-multiplyx 1 sub <-multiplyy 1 sub 10 SetTerrain

"collector" <-dividex <-dividey CreateUnit
<-dividex <-dividey 10 SetTerrain
<-dividex <-dividey 1 add 10 SetTerrain
<-dividex <-dividey 1 sub 10 SetTerrain
<-dividex 1 add <-dividey 10 SetTerrain
<-dividex 1 add <-dividey 1 add 10 SetTerrain
<-dividex 1 add <-dividey 1 sub 10 SetTerrain
<-dividex 1 sub <-dividey 10 SetTerrain
<-dividex 1 sub <-dividey 1 add 10 SetTerrain
<-dividex 1 sub <-dividey 1 sub 10 SetTerrain

#sets the numbers to empty and all the variables i need to control the flow to 0
1 ->nbr1empty
1 ->nbr2empty
0 ->operationchosen
0 ->plus
0 ->minus
0 ->multiply
0 ->divide
0 ->gt0
0 ->gt10
0 ->gt100
0 ->gt1000
0 ->gt10000
0 ->gt100000
0 ->gt1000000
endonce

#if there is no chosen number the first number will be filled with the first number selected by the user
if (<-nbr1empty 1 eq)

if (<-1x <-1y GetUnitAt -1 eq)
1 ->nbr1
0 ->nbr1empty
"collector" <-1x <-1y CreateUnit
endif

if (<-2x <-2y GetUnitAt -1 eq)
2 ->nbr1
0 ->nbr1empty
"collector" <-2x <-2y CreateUnit
endif

if (<-3x <-3y GetUnitAt -1 eq)
3 ->nbr1
0 ->nbr1empty
"collector" <-3x <-3y CreateUnit
endif

if (<-4x <-4y GetUnitAt -1 eq)
4 ->nbr1
0 ->nbr1empty
"collector" <-4x <-4y CreateUnit
endif

if (<-5x <-5y GetUnitAt -1 eq)
5 ->nbr1
0 ->nbr1empty
"collector" <-5x <-5y CreateUnit
endif

if (<-6x <-6y GetUnitAt -1 eq)
6 ->nbr1
0 ->nbr1empty
"collector" <-6x <-6y CreateUnit
endif

if (<-7x <-7y GetUnitAt -1 eq)
7 ->nbr1
0 ->nbr1empty
"collector" <-7x <-7y CreateUnit
endif

if (<-8x <-8y GetUnitAt -1 eq)
8 ->nbr1
0 ->nbr1empty
"collector" <-8x <-8y CreateUnit
endif

if (<-9x <-9y GetUnitAt -1 eq)
9 ->nbr1
0 ->nbr1empty
"collector" <-9x <-9y CreateUnit
endif

endif

#if there is one number and an operation chosen this will find the second
if (<-nbr2empty 1 eq and (<-nbr1empty 0 eq) and (<-operationchosen 1 eq))

if (<-1x <-1y GetUnitAt -1 eq)
1 ->nbr2
0 ->nbr2empty
"collector" <-1x <-1y CreateUnit
endif

if (<-2x <-2y GetUnitAt -1 eq)
2 ->nbr2
0 ->nbr2empty
"collector" <-2x <-2y CreateUnit
endif

if (<-3x <-3y GetUnitAt -1 eq)
3 ->nbr2
0 ->nbr2empty
"collector" <-3x <-3y CreateUnit
endif

if (<-4x <-4y GetUnitAt -1 eq)
4 ->nbr2
0 ->nbr2empty
"collector" <-4x <-4y CreateUnit
endif

if (<-5x <-5y GetUnitAt -1 eq)
5 ->nbr2
0 ->nbr2empty
"collector" <-5x <-5y CreateUnit
endif

if (<-6x <-6y GetUnitAt -1 eq)
6 ->nbr2
0 ->nbr2empty
"collector" <-6x <-6y CreateUnit
endif

if (<-7x <-7y GetUnitAt -1 eq)
7 ->nbr2
0 ->nbr2empty
"collector" <-7x <-7y CreateUnit
endif

if (<-8x <-8y GetUnitAt -1 eq)
8 ->nbr2
0 ->nbr2empty
"collector" <-8x <-8y CreateUnit
endif

if (<-9x <-9y GetUnitAt -1 eq)
9 ->nbr2
0 ->nbr2empty
"collector" <-9x <-9y CreateUnit
endif

endif

#if there is a first number chosen this determines the operation that will be executed
if (<-nbr1empty 0 eq and (<-nbr2empty 1 eq) and (<-operationchosen 0 eq))

if (<-plusx <-plusy GetUnitAt -1 eq)
1 ->plus
1 ->operationchosen
"collector" <-plusx <-plusy CreateUnit
endif

if (<-minusx <-minusy GetUnitAt -1 eq)
1 ->minus
1 ->operationchosen
"collector" <-minusx <-minusy CreateUnit
endif

if (<-multiplyx <-multiplyy GetUnitAt -1 eq)
1 ->multiply
1 ->operationchosen
"collector" <-multiplyx <-multiplyy CreateUnit
endif

if (<-dividex <-dividey GetUnitAt -1 eq)
1 ->divide
1 ->operationchosen
"collector" <-dividex <-dividey CreateUnit
endif

endif

#if all the user's input is done this will calculate the result
if (<-operationchosen 1 eq and (<-nbr2empty 0 eq))

if (<-plus 1 eq)
<-nbr1 <-nbr2 add ->equals
endif

if (<-minus 1 eq)
<-nbr1 <-nbr2 sub ->equals
endif

if (<-multiply 1 eq)
<-nbr1 <-nbr2 mul ->equals
endif

if (<-divide 1 eq)
<-nbr1 <-nbr2 div ->equals
endif

endif

#this determines how long the resulting number is
if (<-equals 9 lte and (<-equals 0 gt))
1 ->gt0
endif

if (<-equals 10 gte and (<-equals 100 lt))
1 ->gt10
endif

if (<-equals 100 gte and (<-equals 1000 lt))
1 ->gt100
endif

if (<-equals 1000 gte and (<-equals 10000 lt))
1 ->gt1000
endif

if (<-equals 10000 gte and (<-equals 100000 lt))
1 ->gt10000
endif

if (<-equals 100000 gte or (<-equals 0 lte))
1 ->error
endif

#this will modify the terrain to show the resulted number
if (->gt0 1 eq)

if (<-equals 1 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@create1
endif

if (<-equals 2 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@create2
endif

if (<-equals 3 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@create3
endif

if (<-equals 4 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@create4
endif

if (<-equals 5 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@create5
endif

endif




:create1
<-currnbrx 1 add <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 1 add <-resultterrain SetTerrain

:create2
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain

:create3
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterrain  SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterain SetTerrain

:create4
<-currnbrx <-currnbry <-resultterain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterain SetTerrain

:create5
<-currnbrx <-currnbry <-resultterain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterain SetTerrain

The display only supports the numbers 1 - 5 because it's at that point that i saw that it has a problem.
The input only supports the numbers 1 - 9 but I will expand this if I get it to work (and after i finished everything else).
The result will be rounded to an integer and won't support numbers below 1, again I will expand this if I get it to work.

I know that there probably is a better (shorter) way to do this but how I did it is the only way I could figure out.

P.S. The coordinates are based on the map in the picture I will attach, the castle at the bottom of the map is for a try of another map I wanted to build but then gave up (because i'm REALLY bad at being creative, the only thing i do good in CW3 custom maps is programming (and playing :P))
P.P.S. I also attached the script in case you want to download it
EDIT:
P.P.P.S. How can I write something on the "spoiler" button? And you probably noticed it somehow - I'm not english/american (i speak german and italian as mother languages (is mother languages the right expression for that?))

Altered code sample to preferred format -G.
Title: Re: CRPL script isn't working
Post by: Clean0nion on November 28, 2013, 01:25:17 PM
1. In your spoiler, take the script out of {code} {/code} and put it into {tt} {/tt}.
I'll take a look at the code now - do you think you can upload the map as well?
Title: Re: CRPL script isn't working
Post by: J on November 28, 2013, 01:25:49 PM
Couldn't check everything because I didn't write the script but this line doesn't look logical:#this will modify the terrain to show the resulted number
if (->gt0 1 eq)
First you assing a value to gt0 then check if another number on the stack is equal to 1. Good chance that you meant to type if(<-gt0 1 eq)
Title: Re: CRPL script isn't working
Post by: Clean0nion on November 28, 2013, 01:29:59 PM
Quote from: J on November 28, 2013, 01:25:49 PM
Couldn't check everything because I didn't write the script but this line doesn't look logical:#this will modify the terrain to show the resulted number
if (->gt0 1 eq)
First you assing a value to gt0 then check if another number on the stack is equal to 1. Good chance that you meant to type if(<-gt0 1 eq)
I think he's right.
Title: Re: CRPL script isn't working
Post by: Annonymus on November 28, 2013, 01:31:57 PM
I uploaded the map.
You're right, it was that line, thank you very much (it still doesen't produce the number i requested but i think i already know why)
Title: Re: CRPL script isn't working
Post by: ThirdParty on November 28, 2013, 01:42:34 PM
In addition to the "->gt0" that ought to be a "<-gt0", you've also got some spots that say "<-resultterain" with one "r", when they ought to say "<-resultterrain" with two "r"s.
Title: Re: CRPL script isn't working
Post by: Annonymus on November 28, 2013, 01:47:41 PM
OH!
Thanks, that was the real reason why the numbers were deformed.

P.S. my problem(s) is (are) solved but i will still leave the topic as it is so i can post here when i encounter another problem or when the script is finished, for you to download it.
Title: Re: CRPL script isn't working
Post by: Annonymus on November 30, 2013, 08:22:46 AM
 ???
I recieved an e-mail telling me michionlion has replied to this topic, but there is nothing...
Title: Re: CRPL script isn't working
Post by: Annonymus on November 30, 2013, 10:05:02 AM
New problem...
I got it to work, and it works perfectly...
until i try to re-initialize the calculator.
I added a function that will set all the variables to their initial state after the result is displayed, but after choosing the first number i can't choose an operation, the emitter will get destroyed and stay destroyed, but as soon as the operation is stored the emitter should be re-built, this means the script doesn't recognise that i choosed an operation, and i can't find out why:


# calculator.crpl
# Created on: 11/28/2013 4:28:53 PM
# ------------------------------------------
$1x:11
$1y:13
$2x:20
$2y:13
$3x:29
$3y:13
$4x:11
$4y:22
$5x:20
$5y:22
$6x:29
$6y:22
$7x:11
$7y:31
$8x:20
$8y:31
$9x:29
$9y:31
$plusx:41
$plusy:18
$minusx:51
$minusy:18
$multiplyx:51
$multiplyy:28
$dividex:41
$dividey:28
$resultx:57
$resulty:20
$resultterrain:10

#creates the collectors and sets terrain under them to 10
once
while not (<-1x <-1y GetUnitAt -1 eq and (<-2x <-2y GetUnitAt -1 eq) and (<-3x <-3y GetUnitAt -1 eq) and (<-4x <-4y GetUnitAt -1 eq) and (<-5x <-5y GetUnitAt -1 eq) and (<-6x <-6y GetUnitAt -1 eq) and (<-7x <-7y GetUnitAt -1 eq) and (<-8x <-8y GetUnitAt -1 eq) and (<-9x <-9y GetUnitAt -1 eq))
repeat

<-1x <-1y GetUnitAt 1 Destroy
<-2x <-2y GetUnitAt 1 Destroy
<-3x <-3y GetUnitAt 1 Destroy
<-4x <-4y GetUnitAt 1 Destroy
<-5x <-5y GetUnitAt 1 Destroy
<-6x <-6y GetUnitAt 1 Destroy
<-7x <-7y GetUnitAt 1 Destroy
<-8x <-8y GetUnitAt 1 Destroy
<-9x <-9y GetUnitAt 1 Destroy
<-plusx <-plusy GetUnitAt 1 Destroy
<-minusx <-minusy GetUnitAt 1 Destroy
<-multiplyx <-multiplyy GetUnitAt 1 Destroy
<-dividex <-dividey GetUnitAt 1 Destroy

endwhile

"collector" <-1x <-1y CreateUnit
<-1x <-1y 10 SetTerrain
<-1x <-1y 1 add 10 SetTerrain
<-1x <-1y 1 sub 10 SetTerrain
<-1x 1 add <-1y 10 SetTerrain
<-1x 1 add <-1y 1 add 10 SetTerrain
<-1x 1 add <-1y 1 sub 10 SetTerrain
<-1x 1 sub <-1y 10 SetTerrain
<-1x 1 sub <-1y 1 add 10 SetTerrain
<-1x 1 sub <-1y 1 sub 10 SetTerrain

"collector" <-2x <-2y CreateUnit
<-2x <-2y 10 SetTerrain
<-2x <-2y 1 add 10 SetTerrain
<-2x <-2y 1 sub 10 SetTerrain
<-2x 1 add <-2y 10 SetTerrain
<-2x 1 add <-2y 1 add 10 SetTerrain
<-2x 1 add <-2y 1 sub 10 SetTerrain
<-2x 1 sub <-2y 10 SetTerrain
<-2x 1 sub <-2y 1 add 10 SetTerrain
<-2x 1 sub <-2y 1 sub 10 SetTerrain

"collector" <-3x <-3y CreateUnit
<-3x <-3y 10 SetTerrain
<-3x <-3y 1 add 10 SetTerrain
<-3x <-3y 1 sub 10 SetTerrain
<-3x 1 add <-3y 10 SetTerrain
<-3x 1 add <-3y 1 add 10 SetTerrain
<-3x 1 add <-3y 1 sub 10 SetTerrain
<-3x 1 sub <-3y 10 SetTerrain
<-3x 1 sub <-3y 1 add 10 SetTerrain
<-3x 1 sub <-3y 1 sub 10 SetTerrain

"collector" <-4x <-4y CreateUnit
<-4x <-4y 10 SetTerrain
<-4x <-4y 1 add 10 SetTerrain
<-4x <-4y 1 sub 10 SetTerrain
<-4x 1 add <-4y 10 SetTerrain
<-4x 1 add <-4y 1 add 10 SetTerrain
<-4x 1 add <-4y 1 sub 10 SetTerrain
<-4x 1 sub <-4y 10 SetTerrain
<-4x 1 sub <-4y 1 add 10 SetTerrain
<-4x 1 sub <-4y 1 sub 10 SetTerrain

"collector" <-5x <-5y CreateUnit
<-5x <-5y 10 SetTerrain
<-5x <-5y 1 add 10 SetTerrain
<-5x <-5y 1 sub 10 SetTerrain
<-5x 1 add <-5y 10 SetTerrain
<-5x 1 add <-5y 1 add 10 SetTerrain
<-5x 1 add <-5y 1 sub 10 SetTerrain
<-5x 1 sub <-5y 10 SetTerrain
<-5x 1 sub <-5y 1 add 10 SetTerrain
<-5x 1 sub <-5y 1 sub 10 SetTerrain

"collector" <-6x <-6y CreateUnit
<-6x <-6y 10 SetTerrain
<-6x <-6y 1 add 10 SetTerrain
<-6x <-6y 1 sub 10 SetTerrain
<-6x 1 add <-6y 10 SetTerrain
<-6x 1 add <-6y 1 add 10 SetTerrain
<-6x 1 add <-6y 1 sub 10 SetTerrain
<-6x 1 sub <-6y 10 SetTerrain
<-6x 1 sub <-6y 1 add 10 SetTerrain
<-6x 1 sub <-6y 1 sub 10 SetTerrain

"collector" <-7x <-7y CreateUnit
<-7x <-7y 10 SetTerrain
<-7x <-7y 1 add 10 SetTerrain
<-7x <-7y 1 sub 10 SetTerrain
<-7x 1 add <-7y 10 SetTerrain
<-7x 1 add <-7y 1 add 10 SetTerrain
<-7x 1 add <-7y 1 sub 10 SetTerrain
<-7x 1 sub <-7y 10 SetTerrain
<-7x 1 sub <-7y 1 add 10 SetTerrain
<-7x 1 sub <-7y 1 sub 10 SetTerrain

"collector" <-8x <-8y CreateUnit
<-8x <-8y 10 SetTerrain
<-8x <-8y 1 add 10 SetTerrain
<-8x <-8y 1 sub 10 SetTerrain
<-8x 1 add <-8y 10 SetTerrain
<-8x 1 add <-8y 1 add 10 SetTerrain
<-8x 1 add <-8y 1 sub 10 SetTerrain
<-8x 1 sub <-8y 10 SetTerrain
<-8x 1 sub <-8y 1 add 10 SetTerrain
<-8x 1 sub <-8y 1 sub 10 SetTerrain

"collector" <-9x <-9y CreateUnit
<-9x <-9y 10 SetTerrain
<-9x <-9y 1 add 10 SetTerrain
<-9x <-9y 1 sub 10 SetTerrain
<-9x 1 add <-9y 10 SetTerrain
<-9x 1 add <-9y 1 add 10 SetTerrain
<-9x 1 add <-9y 1 sub 10 SetTerrain
<-9x 1 sub <-9y 10 SetTerrain
<-9x 1 sub <-9y 1 add 10 SetTerrain
<-9x 1 sub <-9y 1 sub 10 SetTerrain

"collector" <-plusx <-plusy CreateUnit
<-plusx <-plusy 10 SetTerrain
<-plusx <-plusy 1 add 10 SetTerrain
<-plusx <-plusy 1 sub 10 SetTerrain
<-plusx 1 add <-plusy 10 SetTerrain
<-plusx 1 add <-plusy 1 add 10 SetTerrain
<-plusx 1 add <-plusy 1 sub 10 SetTerrain
<-plusx 1 sub <-plusy 10 SetTerrain
<-plusx 1 sub <-plusy 1 add 10 SetTerrain
<-plusx 1 sub <-plusy 1 sub 10 SetTerrain

"collector" <-minusx <-minusy CreateUnit
<-minusx <-minusy 10 SetTerrain
<-minusx <-minusy 1 add 10 SetTerrain
<-minusx <-minusy 1 sub 10 SetTerrain
<-minusx 1 add <-minusy 10 SetTerrain
<-minusx 1 add <-minusy 1 add 10 SetTerrain
<-minusx 1 add <-minusy 1 sub 10 SetTerrain
<-minusx 1 sub <-minusy 10 SetTerrain
<-minusx 1 sub <-minusy 1 add 10 SetTerrain
<-minusx 1 sub <-minusy 1 sub 10 SetTerrain

"collector" <-multiplyx <-multiplyy CreateUnit
<-multiplyx <-multiplyy 10 SetTerrain
<-multiplyx <-multiplyy 1 add 10 SetTerrain
<-multiplyx <-multiplyy 1 sub 10 SetTerrain
<-multiplyx 1 add <-multiplyy 10 SetTerrain
<-multiplyx 1 add <-multiplyy 1 add 10 SetTerrain
<-multiplyx 1 add <-multiplyy 1 sub 10 SetTerrain
<-multiplyx 1 sub <-multiplyy 10 SetTerrain
<-multiplyx 1 sub <-multiplyy 1 add 10 SetTerrain
<-multiplyx 1 sub <-multiplyy 1 sub 10 SetTerrain

"collector" <-dividex <-dividey CreateUnit
<-dividex <-dividey 10 SetTerrain
<-dividex <-dividey 1 add 10 SetTerrain
<-dividex <-dividey 1 sub 10 SetTerrain
<-dividex 1 add <-dividey 10 SetTerrain
<-dividex 1 add <-dividey 1 add 10 SetTerrain
<-dividex 1 add <-dividey 1 sub 10 SetTerrain
<-dividex 1 sub <-dividey 10 SetTerrain
<-dividex 1 sub <-dividey 1 add 10 SetTerrain
<-dividex 1 sub <-dividey 1 sub 10 SetTerrain

#sets the numbers to empty  and all the variables I need to control the flow to 0
1 ->nbr1empty
1 ->nbr2empty
0 ->operationchosen
0 ->plus
0 ->minus
0 ->multiply
0 ->divide
0 ->gt0
0 ->gt10
0 ->gt100
0 ->gt1000
0 ->gt10000
0 ->gt100000
0 ->gt1000000
endonce

#if there is no chosen number the first number will be filled with the first number selected by the user
if (<-nbr1empty 1 eq)

if (<-1x <-1y GetUnitAt -1 eq)
1 ->nbr1
0 ->nbr1empty
"collector" <-1x <-1y CreateUnit
endif

if (<-2x <-2y GetUnitAt -1 eq)
2 ->nbr1
0 ->nbr1empty
"collector" <-2x <-2y CreateUnit
endif

if (<-3x <-3y GetUnitAt -1 eq)
3 ->nbr1
0 ->nbr1empty
"collector" <-3x <-3y CreateUnit
endif

if (<-4x <-4y GetUnitAt -1 eq)
4 ->nbr1
0 ->nbr1empty
"collector" <-4x <-4y CreateUnit
endif

if (<-5x <-5y GetUnitAt -1 eq)
5 ->nbr1
0 ->nbr1empty
"collector" <-5x <-5y CreateUnit
endif

if (<-6x <-6y GetUnitAt -1 eq)
6 ->nbr1
0 ->nbr1empty
"collector" <-6x <-6y CreateUnit
endif

if (<-7x <-7y GetUnitAt -1 eq)
7 ->nbr1
0 ->nbr1empty
"collector" <-7x <-7y CreateUnit
endif

if (<-8x <-8y GetUnitAt -1 eq)
8 ->nbr1
0 ->nbr1empty
"collector" <-8x <-8y CreateUnit
endif

if (<-9x <-9y GetUnitAt -1 eq)
9 ->nbr1
0 ->nbr1empty
"collector" <-9x <-9y CreateUnit
endif

endif

#if there is one number and an operation chosen this will find the second
if (<-nbr2empty 1 eq and (<-nbr1empty 0 eq) and (<-operationchosen 1 eq))

if (<-1x <-1y GetUnitAt -1 eq)
1 ->nbr2
0 ->nbr2empty
"collector" <-1x <-1y CreateUnit
endif

if (<-2x <-2y GetUnitAt -1 eq)
2 ->nbr2
0 ->nbr2empty
"collector" <-2x <-2y CreateUnit
endif

if (<-3x <-3y GetUnitAt -1 eq)
3 ->nbr2
0 ->nbr2empty
"collector" <-3x <-3y CreateUnit
endif

if (<-4x <-4y GetUnitAt -1 eq)
4 ->nbr2
0 ->nbr2empty
"collector" <-4x <-4y CreateUnit
endif

if (<-5x <-5y GetUnitAt -1 eq)
5 ->nbr2
0 ->nbr2empty
"collector" <-5x <-5y CreateUnit
endif

if (<-6x <-6y GetUnitAt -1 eq)
6 ->nbr2
0 ->nbr2empty
"collector" <-6x <-6y CreateUnit
endif

if (<-7x <-7y GetUnitAt -1 eq)
7 ->nbr2
0 ->nbr2empty
"collector" <-7x <-7y CreateUnit
endif

if (<-8x <-8y GetUnitAt -1 eq)
8 ->nbr2
0 ->nbr2empty
"collector" <-8x <-8y CreateUnit
endif

if (<-9x <-9y GetUnitAt -1 eq)
9 ->nbr2
0 ->nbr2empty
"collector" <-9x <-9y CreateUnit
endif

endif

#if there is a first number chosen this determines the operation that will be executed
if (<-nbr1empty 0 eq and (<-nbr2empty 1 eq) and (<-operationchosen 0 eq))

if (<-plusx <-plusy GetUnitAt -1 eq)
1 ->plus
1 ->operationchosen
"collector" <-plusx <-plusy CreateUnit
endif

if (<-minusx <-minusy GetUnitAt -1 eq)
1 ->minus
1 ->operationchosen
"collector" <-minusx <-minusy CreateUnit
endif

if (<-multiplyx <-multiplyy GetUnitAt -1 eq)
1 ->multiply
1 ->operationchosen
"collector" <-multiplyx <-multiplyy CreateUnit
endif

if (<-dividex <-dividey GetUnitAt -1 eq)
1 ->divide
1 ->operationchosen
"collector" <-dividex <-dividey CreateUnit
endif

endif

#if all the user's input is done this will calculate the result
if (<-operationchosen 1 eq and (<-nbr2empty 0 eq))

if (<-plus 1 eq)
<-nbr1 <-nbr2 add ->equals
endif

if (<-minus 1 eq)
<-nbr1 <-nbr2 sub ->equals
endif

if (<-multiply 1 eq)
<-nbr1 <-nbr2 mul ->equals
endif

if (<-divide 1 eq)
<-nbr1 <-nbr2 div ->equals
endif

endif

#this determines how long the resulting number is
if (<-equals 9 lte and (<-equals 0 gt))
1 ->gt0
endif

if (<-equals 10 gte and (<-equals 100 lt))
1 ->gt10
endif

if (<-equals 100 gte and (<-equals 1000 lt))
1 ->gt100
endif

if (<-equals 1000 gte and (<-equals 10000 lt))
1 ->gt1000
endif

if (<-equals 10000 gte and (<-equals 100000 lt))
1 ->gt10000
endif

if (<-equals 100000 gte or (<-equals 0 lte))
1 ->error
endif

#this will modify the terrain to show the resulted number
if (<-gt0 1 eq)

if (<-equals 1 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create1
@initialize
endif

if (<-equals 2 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create2
@initialize
endif

if (<-equals 3 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create3
@initialize
endif

if (<-equals 4 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create4
@initialize
endif

if (<-equals 5 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create5
@initialize
endif

if (<-equals 6 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create6
@initialize
endif

if (<-equals 7 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create7
@initialize
endif

if (<-equals 8 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create8
@initialize
endif

if (<-equals 9 eq)
<-resultx ->currnbrx <-resulty ->currnbry
@setGroundToZero
@create9
@initialize
endif

endif




:create1
<-currnbrx 1 add <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 1 add <-resultterrain SetTerrain

:create2
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain

:create3
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterrain  SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain

:create4
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain

:create5
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain

:create6
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 add <-resultterrain SetTerrain

:create7
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain

:create8
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterrain SetTerrain

:create9
<-currnbrx <-currnbry <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 add <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 add <-resultterrain SetTerrain
<-currnbrx <-currnbry 1 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 1 add <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx <-currnbry 2 sub <-resultterrain SetTerrain
<-currnbrx 2 add <-currnbry 1 sub <-resultterrain SetTerrain

:initialize
1 ->nbr1empty
1 ->nbr2empty
0 ->operationchosen
0 ->plus
0 ->minus
0 ->multiply
0 ->divide
0 ->gt0
0 ->gt10
0 ->gt100
0 ->gt1000
0 ->gt10000
0 ->gt100000
0 ->gt1000000

:setGroundToZero
<-currnbrx <-currnbry 1 SetTerrain
<-currnbrx 1 add <-currnbry 1 SetTerrain
<-currnbrx 2 add <-currnbry 1 SetTerrain
<-currnbrx 2 add <-currnbry 1 add 1 SetTerrain
<-currnbrx 2 add <-currnbry 2 add 1 SetTerrain
<-currnbrx 1 add <-currnbry 2 add 1 SetTerrain
<-currnbrx <-currnbry 2 add 1 SetTerrain
<-currnbrx <-currnbry 1 sub 1 SetTerrain
<-currnbrx 2 add <-currnbry 2 sub 1 SetTerrain
<-currnbrx 1 add <-currnbry 2 sub 1 SetTerrain
<-currnbrx <-currnbry 2 sub 1 SetTerrain
<-currnbrx <-currnbry 1 add 1 SetTerrain
<-currnbrx 2 add <-currnbry 1 sub 1 SetTerrain


The map is still the same as in the top-post, I attached the script.
Clean0nion: grauniad wants me to use (code), sorry

P.S. If i call a variable i never declared, what value do i get? 0? null? and if it's null, can i somehow set the variable to null?

EDIT:
somehow it fixed itself while i was continueing to work on a different part of the script.
Title: Re: CRPL script isn't working
Post by: Michionlion on November 30, 2013, 12:03:43 PM
Quote from: Annonymus on November 30, 2013, 08:22:46 AM
???
I recieved an e-mail telling me michionlion has replied to this topic, but there is nothing...

Sorry, I deleted my post.
Title: Re: CRPL script isn't working
Post by: Annonymus on November 30, 2013, 12:05:39 PM
in the meanwhile i got another reply by harkler that apparently got deleted, too!
Title: Re: CRPL script isn't working
Post by: Michionlion on November 30, 2013, 12:10:55 PM
Most of the time people use the 'Show unread posts since your last visit' link at the top of the forum, which (I think) disregards removed posts.  Now back on-topic... :P