CRPL Problem

Started by theo, March 17, 2015, 02:23:05 PM

Previous topic - Next topic

theo

This is my first post.
Hello, could someone help me, my CRPL script isn't working. It's my first attempt at CRPL. It should start creating AC rains at a set interval after it receives a set number of AC packets. Also, after it receives the first packet it should start changing images from a recolored slip emmiter to a crater. After it receives all AC packets it needs it should change it's image to a 3-rd image, wait 60 frames change it's image again, wait 1 frame and lose it's ammo and don't request more, become invisible, not connectable to your power grid, and stop taking space on the map. I didn't make the AC rain part yet but the first part doesn't work.
Here's what I did: I made my script, opened the scrips tab of the world editor, add and compile my script, add it to my CRPL core, change the settings of the core, save and test my map, the core requests packets but doesn't do anything when it receives packets.

Here's my scrips as seen in notepad++:

# AC Rain Device.crpl
# ------------------------------------------
$AMT:-2000
$MAXAMMO:10
$INTERVAL:3000
$SHOWMESSAGE:1
$SHOWSECONDPARTOFTHEMESSAGE:0
once
60 "CONST_ACPACKETREQUESTDELAY" Self SetUnitAttribute
true "CONST_TAKEMAPSPACE" Self SetUnitAttribute
true "CONST_REQUESTACPACKETS" Self SetUnitAttribute
true "CONST_CONNECTABLE" Self SetUnitAttribute
false "CONST_SHOWAMMOACBAR" Self SetUnitAttribute
<-MAXAMMO "CONST_MAXAMMOAC" Self SetUnitAttribute
0 "CONST_AMMOAC" Self SetUnitAttribute
endonce
0 ->enabled
"Custom0" ->nextImage
0 ->finalised
"CONST_AMMOAC" Self GetUnitAttribute neq0 <-enabled eq0 and if
<-SHOWMESSAGE 1 eq if
ClearConversation
"Hey, a command node just sent a package to a slip emmiter?" 0 AddConversationMessage
"Looks like human tech keeps it open. And it can generate AC... from AC?" 0 AddConversationMessage
"Yeah, but I cannot retrieve the equipment, it would explode if disconnected from the slip emitter." 1 AddConversationMessage
"If it receives enough AC it will create AC rains periodically." 1 AddConversationMessage
"Then I'll activate it." 0 AddConversationMessage
<-SHOWSECONDPARTOFTHEMESSAGE 1 eq if
"If you activate it I may be able to scan the equipment." 1 AddConversationMessage
"krj8ow3ur8934h8934h98rt3huoth34iurthu3il4rtho3w4hrtwo8th 4vui34hvuiehnr34hliru34 hitvu3hr r3 grt 4iortg3i4ur g4eiu trg34uir tio4wr io3u42 riou234rhiou24hriu34hr3o4ir4 h34 hruiow34h rpo43h t3po4iu hrp34uhtr34uhrop34htr34uhtui4wh3t i34hut uirhtiou34htlu43h5tuli34htou34htiuo4htuih4tuih3utoh34" 3 AddConversationMessage
"When will it give up, it won't hack this ship." 0 AddConversationMessage
endif
ShowConversation
endif
15 SetTimer0
1 ->enabled
endif
"CONST_AMMOAC" Self GetUnitAttribute <-MAXAMMO eq <-finalised eq0 and if
false "CONST_CONNECTABLE" Self SetUnitAttribute
false "CONST_REQUESTACPACKETS" Self SetUnitAttribute
0 "CONST_AMMOAC" Self SetUnitAttribute
"Custom2" "main" Self SetImage
60 Delay
"Custom3" "main" Self SetImage
1 Delay
"None" "main" Self SetImage
false "CONST_TAKEMAPSPACE" Self SetUnitAttribute
1 ->finalised
endif
GetTimer0 eq0 <-enabled neq0 and <-finalised eq0 and if
<-nextImage "main" Self SetImage
<-nextImage "Custom0" eq if
"Custom1" ->nextImage
endif
<-nextImage "Custom1" eq if
"Custom0" ->nextImage
endif
15 SetTimer0
endif
# i didn't make the AC rain part yet, but the first part doesn't work

I also attached my file to this post.

TheTiconTech

#1
OK. At first, GetUnitAttribute and SetUnitAttribute take arguments in a strict order:
[UID of a unit] [Name of the attribute] GetUnitAttribute
[UID of a unit] [Name of the attribute] [Value] SetUnitAttribute

So your first
60 "CONST_ACPACKETREQUESTDELAY" Self SetUnitAttribute

Should look like
Self "CONST_ACPACKETREQUESTDELAY" 60 SetUnitAttribute

The idea is good, and i think i can represent it in much less strings, but you also change images. Well, try changing arguments' order and leave feedback. Also a very cool page for learners:

http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference

Every CRPL command with description, syntaxis and (on 50% of pages) examples.

UPD: you're a monster. Conversation commands take arguments like [number of a character] [message]. NOT reverse! Look CRPL Reference!

warren

Also don't forget to drop all the quotes around constants.

theo

Quote from: TheTiconTech on March 18, 2015, 01:11:19 PM
OK. At first, GetUnitAttribute and SetUnitAttribute take arguments in a strict order:
[UID of a unit] [Name of the attribute] GetUnitAttribute
[UID of a unit] [Name of the attribute] [Value] SetUnitAttribute

So your first
60 "CONST_ACPACKETREQUESTDELAY" Self SetUnitAttribute

Should look like
Self "CONST_ACPACKETREQUESTDELAY" 60 SetUnitAttribute

The idea is good, and i think i can represent it in much less strings, but you also change images. Well, try changing arguments' order and leave feedback. Also a very cool page for learners:

http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference

Every CRPL command with description, syntaxis and (on 50% of pages) examples.

UPD: you're a monster. Conversation commands take arguments like [number of a character] [message]. NOT reverse! Look CRPL Reference!
Sorry, I thought the arguments at crpl reference MUST be taken in reversed order.
Sorry, my English isn't very good, I'm from Romania.

theo

Modified my code, but it does not work as intented.
As soon as I unpause the game pauses again to show me the message, when I unpause the CRPL core telepors to the edge of the map and the AC rain does not appear. Here's the script:
# AC Rain Device.crpl
# ------------------------------------------
$AMT:-2000
$MAXAMMO:10
$INTERVAL:3000
$SHOWMESSAGE:1
$SHOWSECONDPARTOFTHEMESSAGE:0
$AMMOREQUESTDELAY:60
once
Self "CONST_ACPACKETREQUESTDELAY" <-AMMOREQUESTDELAY SetUnitAttribute
Self "CONST_TAKEMAPSPACE" true SetUnitAttribute
Self "CONST_REQUESTACPACKETS" true SetUnitAttribute
Self "CONST_CONNECTABLE" true SetUnitAttribute
Self "CONST_SHOWAMMOACBAR" false SetUnitAttribute
Self "CONST_MAXAMMOAC" <-MAXAMMO SetUnitAttribute
endonce
0 ->enabled
"Custom0" ->nextImage
0 ->finalised
Self "CONST_AMMOAC" GetUnitAttribute neq0 <-enabled eq0 and if
<-SHOWMESSAGE 1 eq if
ClearConversation
0 "Hey, a command node just sent a package to a slip emmiter?" AddConversationMessage
0 "Looks like human tech keeps it open. And it can generate AC... from AC?" AddConversationMessage
1 "Yeah, but I cannot retrieve the equipment, it would explode if disconnected from the slip emitter." AddConversationMessage
1 "If it receives enough AC it will create AC rains periodically." AddConversationMessage
0 "Then I'll activate it." 0 AddConversationMessage
<-SHOWSECONDPARTOFTHEMESSAGE 1 eq if
1 "If you activate it I may be able to scan the equipment." AddConversationMessage
3 "krj8ow3ur8934h8934h98rt3huoth34iurthu3il4rtho3w4hrtwo8th 4vui34hvuiehnr34hliru34 hitvu3hr r3 grt 4iortg3i4ur g4eiu trg34uir tio4wr io3u42 riou234rhiou24hriu34hr3o4ir4 h34 hruiow34h rpo43h t3po4iu hrp34uhtr34uhrop34htr34uhtui4wh3t i34hut uirhtiou34htlu43h5tuli34htou34htiuo4htuih4tuih3utoh34" AddConversationMessage
0 "When will it give up, it won't hack this ship." AddConversationMessage
endif
ShowConversation
endif
15 SetTimer0
1 ->enabled
endif
Self "CONST_AMMOAC" GetUnitAttribute <-MAXAMMO eq <-finalised eq0 and if
Self "CONST_CONNECTABLE" false SetUnitAttribute
Self "CONST_REQUESTACPACKETS" false SetUnitAttribute
Self "CONST_AMMOAC" 0 SetUnitAttribute
Self "main" "Custom2" SetImage
60 Delay
Self "main" "Custom3" SetImage
5 Delay
Self "main" "None" SetImage
Self "CONST_TAKEMAPSPACE" false SetUnitAttribute
<-INTERVAL SetTimer1
1 ->finalised
endif
GetTimer0 eq0 <-enabled neq0 and <-finalised eq0 and if
Self "main" <-nextImage SetImage
<-nextImage "Custom0" eq if
"Custom1" ->nextImage
endif
<-nextImage "Custom1" eq if
"Custom0" ->nextImage
endif
15 SetTimer0
endif
<-finalised 1 eq GetTimer1 eq0 and if
<-AMT MakeRain
<-INTERVAL SetTimer1
endif

J

Quote from: warren on March 18, 2015, 01:22:15 PM
Also don't forget to drop all the quotes around constants.
So
Self "CONST_TAKEMAPSPACE" true SetUnitAttribute
should be
Self CONST_TAKEMAPSPACE true SetUnitAttribute

All CONSTs put a number on the stack. If you put a string on the stack (with "") it defaults a the number which is the same number of CONST_COORDX, that's why it goes to the edge of the map.

theo

Quote from: J on March 18, 2015, 05:34:05 PM
Quote from: warren on March 18, 2015, 01:22:15 PM
Also don't forget to drop all the quotes around constants.
So
Self "CONST_TAKEMAPSPACE" true SetUnitAttribute
should be
Self CONST_TAKEMAPSPACE true SetUnitAttribute

All CONSTs put a number on the stack. If you put a string on the stack (with "") it defaults a the number which is the same number of CONST_COORDX, that's why it goes to the edge of the map.
I removed the quotes, now it works as intended until the AC rain part. After the core becomes invisible it does nothing.
Also I removed the changing images, after receiving first packet it changes it's image only once.

warren


TheTiconTech

Quote
Sorry, I thought the arguments at crpl reference MUST be taken in reversed order.
Sorry, my English isn't very good, I'm from Romania.

Well, a stack acts like a stack of plates. You put on top, you take from top. So the arguments [1] [2] [3] are taken in order [3] [2] [1] by principe already.
Mine english is bad too, I'm from Russia  ;D

theo

Quote from: warren on March 19, 2015, 03:43:56 AM
MakeRain takes two arguments.
Modified the code, still does not work.
# AC Rain Device.crpl
# ------------------------------------------
$AMT:-20000
$MAXAMMO:10
$INTERVAL:900
$SHOWMESSAGE:1
$SHOWSECONDPARTOFTHEMESSAGE:0
$AMMOREQUESTDELAY:60
$DROPLETSNUMBER:50
once
Self CONST_ACPACKETREQUESTDELAY <-AMMOREQUESTDELAY SetUnitAttribute
Self CONST_TAKEMAPSPACE true SetUnitAttribute
Self CONST_REQUESTACPACKETS true SetUnitAttribute
Self CONST_CONNECTABLE true SetUnitAttribute
Self CONST_SHOWAMMOACBAR false SetUnitAttribute
Self CONST_MAXAMMOAC <-MAXAMMO SetUnitAttribute
endonce
0 ->img
0 ->enabled
0 ->finalised
Self CONST_AMMOAC GetUnitAttribute neq0 <-enabled eq0 GetTimer0 eq0 and and if
1 ->enabled
<-SHOWMESSAGE 1 eq if
0 ->SHOWMESSAGE
ClearConversation
0 "Hey, a command node just sent a package to a slip emmiter?" AddConversationMessage
0 "Looks like human tech keeps it open. And it can generate AC... from AC?" AddConversationMessage
1 "Yeah, but I cannot retrieve the equipment, it would explode if disconnected from the slip emitter." AddConversationMessage
1 "If it receives enough AC it will create AC rains periodically." AddConversationMessage
0 "Then I'll activate it." 0 AddConversationMessage
<-SHOWSECONDPARTOFTHEMESSAGE 1 eq if
1 "If you activate it I may be able to scan the equipment." AddConversationMessage
2 "krj8ow3ur8934h8934h98rt3huoth34iurthu3il4rtho3w4hrtwo8th 4vui34hvuiehnr34hliru34 hitvu3hr r3 grt 4iortg3i4ur g4eiu trg34uir tio4wr io3u42 riou234rhiou24hriu34hr3o4ir4 h34 hruiow34h rpo43h t3po4iu hrp34uhtr34uhrop34htr34uhtui4wh3t i34hut uirhtiou34htlu43h5tuli34htou34htiuo4htuih4tuih3utoh34" AddConversationMessage
0 "When will it give up, it won't hack this ship." AddConversationMessage
endif
ShowConversation
PauseGame
endif
Self "main" "Custom0" SetImage
endif
Self CONST_AMMOAC GetUnitAttribute <-MAXAMMO eq <-finalised eq0 and if
Self CONST_CONNECTABLE false SetUnitAttribute
Self CONST_REQUESTACPACKETS false SetUnitAttribute
Self CONST_AMMOAC 0 SetUnitAttribute
Self "main" "Custom2" SetImage
60 Delay
Self "main" "Custom3" SetImage
5 Delay
Self "main" "None" SetImage
Self CONST_TAKEMAPSPACE false SetUnitAttribute
<-INTERVAL SetTimer0
1 ->finalised
endif
<-finalised 1 eq GetTimer0 eq0 and if
<-DROPLETSNUMBER <-AMT MakeRain
<-INTERVAL SetTimer0
endif

J

#10
Quote from: TheTiconTech on March 19, 2015, 04:16:42 AM
Quote
Sorry, I thought the arguments at crpl reference MUST be taken in reversed order.
Sorry, my English isn't very good, I'm from Romania.
Well, a stack acts like a stack of plates. You put on top, you take from top. So the arguments [1] [2] [3] are taken in order [3] [2] [1] by principe already.
Well, that would be correct if the code interpreter didn't auto-reverse it for you. If you put the arguments in the order given by the wiki, they are in correct order. So if the wiki says the arguments are [1] [2] [3], you should write '[1] [2] [3] function'. The internal code that reads CRPL first pops [3] from the stack, then [2] and then [1].

warren

#11
I believe the maximum droplet size is ~2000 not ~20000.

Three testing commands I recommend using:
ShowTraceLog
ClearTraceLog

Place those near the start of the file, if you made any hidden mistakes, they sometimes show up on the tracelog.

"Hello" trace.

Place this right next to the MakeRain command. If it does not show up in the trace log, it means your problem is that program flow is not reaching MakeRain. Check your if statements.

edit:
It would help in reading the code if it was indented.

TheDutcher

Quote from: J on March 19, 2015, 11:26:14 AM
Quote from: TheTiconTech on March 19, 2015, 04:16:42 AM
Quote
Sorry, I thought the arguments at crpl reference MUST be taken in reversed order.
Sorry, my English isn't very good, I'm from Romania.
Well, a stack acts like a stack of plates. You put on top, you take from top. So the arguments [1] [2] [3] are taken in order [3] [2] [1] by principe already.
Well, that would be correct if the code interpreter didn't auto-reverse it for you. If you put the arguments in the order given by the wiki, they are in correct order. So if the wiki says the arguments are [1] [2] [3], you should write '[1] [2] [3] function'. The internal code that reads CRPL first pops [3] from the stack, then [2] and then [1].
Isn't that exactly what he said? You pop them in normal order in, but they're read in the reversed order. That's the whole point of a stack language.

P.S.
With
Quote from: TheTiconTech on March 19, 2015, 04:16:42 AM
are taken in order [3] [2] [1]
he meant that first 3 is read (popped), then 2 and then 1, just like we read it.

theo

I finished the script. Thanks to warren for the TraceLog tip.
Anyone can use my script, but put my name in the credits.
Here's the script, if you modify it please post it in my SubspaceSlip Artificial AntiEmitter post.

theo

#14
I'll lock this topic, use SubspaceSlip Artificial AntiEmitter to talk about this script.

Provided a link to the referenced topic. -K75