creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
bookmarks | search | post new topic
Development Forum
old
Question to Creatures Village Coders   
bedalton

bedalton



  7/1/2020

So I am programming a CAOS editor for IntelliJ, and I am having a hard time parsing TRAN and CHAR in Creatures Village CAOS. According to the docs I found on ghostfishe.net Here, TRAN and CHAR have two different forms of rvalues.

TRAN (integer) XPOS (integer) YPOS (integer)
TRAN (string) KEY_CODE (integer)

CHAR (integer) STRING (string) INDEX (integer)
CHAR (string)

I am having trouble writing a parser to handle both versions of the code. I have decided to have it read a given command based on what is expected (ie. Integer or String) which solves the problem most of the time, but the parser sometimes has problems when a value of type 'anything' is expected such as P1 and P2 in the command:
CAOS (string) INLINE (integer) STATE_TRANS (integer) P1 (anything) P2 (anything) COMMANDS (string) THROWS (integer) CATCHES (integer) REPORT (variable)

The parser performs unpredictably and cannot tell which command I am trying to use. It pretty causes erroneous errors to be reported, messes up type hinting and causes weird text wrapping and indenting problems. The parser will randomly read one form over the other and may read too many or too few values depending on what you are trying to do.

Commands affected are TYPE, MESG WRT+, CAOS, and PRT: SEND. Passing CHAR or TRAN to any of these causes unexpected parsing behavior.

The question is, should I still include the CV language when I release the plugin. At the moment I am thinking I shouldn't, as it is not reliable when used in this context, though randomly generating thousands of lines of code, the parser works well. But if you try to pass the TRAN value for a pixel as P1 or P2 for example, the editor may show errors where there aren't any.

What do you guys think, do I include or exclude the Creatures Village language? C1,C2,C3 and DS all work really well. So I still plan to release those. Are these cases handled well in the official CV editor?

Please let me know if anyone has any thoughts or opinions.

 
Vermidia

Vermidia



  7/1/2020

As far as I know there is no official CV editor. The closest you can get it the C3 & DS Caos tool.

It would be cool for CV to have an editor though.


You know...wait...nevermind... wait...no...umm...maybe later...
 
Papriko
Peppery One

Papriko



  7/1/2020

You would probably run into similar problems with C3/DS. Except for a very very few version exclusive commands, CV's engine is almost identical to them in most regards. CHAR, MESG WRT+, CAOS... Those are all commands which also appear in C3/DS.

Would it be possible to count the number of arguments of the parent command? CAOS for example seems to be taking 8 arguments if I see it right. So when TRAN is passed as an argument to CAOS, you could count the number of arguments CAOS ends up depending which version of TRAN you assume.
Then you could double-check the data types to make sure it actually works out.


As for TYPE in particular... It might be a bit of a special case. The whole point of TYPE is to figure out what data type a given input actually is. It's mainly supposed to be used on dynamic variables like OV## and VA##.
It's unlikely that CHAR and TRAN actually ever get passed as an argument to it, because the code author would know which one they use and subsequently which data type is to be expected. If you still want to make your parser "bulletproof" in that regard, which is very honorable, I'd go for the counting method again. Try to work it out based on the command TYPE is passed as an argument to.


Lets play plants! Photosynthesis... Photosynthesis... Photosynthesis...
 
bedalton

bedalton



  7/2/2020

Thank you both for the input, I really appreciate it.

I never played Creatures Village, and assumed there was an editor for it.

I went through the Docs for all 5 Creatures games, and only CV has TRAN and CHAR with two versions of rvalues each. Every other variant is pretty straightforward, one version of the command as command, lvalue or rvalue or any combination of those with a single way to read each.

That is a fair point about TYPE, so it is one less thing I would have to be worried about, but I honestly do not know how the official game would have handled this problem.

I am using a parser engine I am pretty familiar with (and one I have to use for IntelliJ), but I honestly do not know how to resolve what is needed in my head, let alone how to tell a computer to do it. If a type is specific for int or string, all is well, but I do not know how the original game would handle it when passed as a parameter to any of those methods that allow 'anything' values

The following code is flagged as invalid in my plugin, when it would be valid if it only read the version of TRAN with one argument:
dbg: outs caos 0 1 0 tran 1 1 1 1 va01

CHAR can be helped if I detect if the first parameter is a string, but I cannot resolve variables to their type when it is being parsed, only after it is parsed. So this method would only work for literal strings or commands that return a string. This fails though if the next parameter passed to these methods is a string itself, as it would try to consume that as well, when it should consume nothing.

I am writing to the IntelliJ plugin development forum to see if there is a way to allow the user to alter the tree in a way that is persisted when parsing, because I only know how to add data after it has already been parsed. If I can do that, then a user can specifically request one format or the other, but I do not know if this is possible.

TRAN cannot be helped by checking for the next value, as both versions have an integer as their first parameter. The plugin tends to assume it wants as many parameters as possible, and I imagine that TRAN for pixels would be used more than TRAN for translator, but I do not actually know.

These are I am hoping edge cases, I do not know how many CAOS coders who use my plugin will pass TRAN or CHAR as P1 or P2 to MESG WRT+ or CAOS and will be trying to use the versions for text compounds, but it is a possibility. I really do not know how to proceed with the CV plugin.

 
Papriko
Peppery One

Papriko



  7/2/2020

bedalton wrote:
TRAN cannot be helped by checking for the next value, as both versions have an integer as their first parameter. The plugin tends to assume it wants as many parameters as possible, and I imagine that TRAN for pixels would be used more than TRAN for translator, but I do not actually know.

What I meant is: when you encounter one of the problematic commands like CAOS, couldn't you tell your parser to count how many values it finds until the next command type operation is encountered? So, if e.g. TRAN comes as P2 argument of CAOS, you will either have 5 or 6 values (COMMANDS, THROWS, CATCHES and REPORT for CAOS, and either 1 or 2 for TRAN) until the next independent command shows up. Couldn't you use that number to work out which one it is? 5 means it is the single argument TRAN, 6 is the two argument TRAN and any other number of values is just outright wrong.
You could probably still confuse the parser by using TRAN multiple times, but at this point it becomes an intentional stress-test rather than a realistic coding situation.



bedalton wrote:
These are I am hoping edge cases, I do not know how many CAOS coders who use my plugin will pass TRAN or CHAR as P1 or P2 to MESG WRT+ or CAOS and will be trying to use the versions for text compounds, but it is a possibility. I really do not know how to proceed with the CV plugin.

Quite frankly, probably not many. I don't know how familiar with scripting for these games, but P1 and P2 are used as arguments for scripts, that's why they are data type "anything". They are context-dependent for the script you are calling in that particular moment. MESG WRT+ triggers a given script ID in a targeted agent. For example, if you have a GUI agent which has a custom button script of ID 1000, you could remotely trigger that script by MESG-ing it 1000. All P1 and P2 are for is to pass values to scripts invoked this way.

This system is used for the "speech bubble factory" for example. As the name suggests, it creates all the speech bubbles in the game, like the ones when norns talk or when the hand speaks an order. It has a custom script literally just for spitting out speech bubbles.
You can MESG WRT+ it with P1 as the speaking agent and P2 as the spoken text, then it does the rest of the work for you, creating the speech bubble agent, setting the text, positioning and attaching the bubble to the speaking agent and making sure it finally disappears.

The CAOS command is in a similar vein. It takes the string that is the COMMANDS argument, spawns an entirely new instance of the CAOS language parser that runs for every agent, and then runs the COMMANDS string as a script within that. It's mainly featured in the cheat console in C3/DS, though other similarly intricate applications are imaginable. In essence, it's purpose is to write and execute entire scripts on the fly. Why would you even need P1 and P2 for that, rather than letting the script that is literally being composed at runtime figure out whatever values it needs? I don't know. Maybe there are use cases for it. Maybe it is a compatibility thing.

The point I am trying to make is this: MESG WRT+ and CAOS are some high tier commands which are used to invoke other scripts in one way or another. It is highly unlikely that something like CHAR "Returns the last character received by the currently selected character translator." is passed as an argument. When the script needs it, it can very much call CHAR itself, no need to do this whole P1 P2 hassle. Similar story with TRAN.
I say you can see this as a personal challenge if you want, but don't drive yourself crazy if you can't find a solution. This isn't exactly the kind of bug you'd get crucified over.



Little side note:

bedalton wrote:
The following code is flagged as invalid in my plugin, when it would be valid if it only read the version of TRAN with one argument:
dbg: outs caos 0 1 0 tran 1 1 1 1 va01

Technically, that isn't right either. As mentioned before, that command has a string as fifth argument. You gotta put some dummy code in there that doesn't confuse your parser all too much, e.g. dbg: outs caos 0 1 0 tran 1 "outv mows" 1 1 va01


Lets play plants! Photosynthesis... Photosynthesis... Photosynthesis...
 
bedalton

bedalton



  7/3/2020

Thank you very much for your thorough reply, I really, really appreciate it. I actually do not know how to get the parser to count the totals manually. that is part of the problem. IntelliJ uses BNF grammar with some parser utils written in Java, and I actually do not know how to tell it to be more manual.

My first attempt at writing the grammar involved trying to read the words as a stream, and interpreting it as it went, but that led to a simple grammar, but a nightmare for me to unpack, validate and add completions to. It also was impossible for me to add type hints to.

Instead I added 2,411 command entries into a database, and wrote a script to write out a command specific grammar. I needed to add interfaces to the commands, and the first version of the grammar was 16,000 lines long, which was insane, so I combined all commands with similar arguments of length and type. It is now 7,088 lines long, and I do not know how to take it from breaking things down for me, to breaking things down myself only sometimes. Most lines in the grammar are repetitive wiring code so that I can validate commands and variable types.

Honestly, you have made me feel a lot better about focusing my efforts elsewhere.

It's funny that you pointed out my dbg: outs ... tran example, because when I was messing around with it after I had posted it, and added an extra 1 to complete TRAN the way the parser expected, it marked one of my 1's as expecting a string value. I then had to click on the command to see the description for the command in usage and that parameter 5 was meant to be a command string. That kind of thing would have been impossible when parsing things manually myself, word by word.

As I am only an amateur plugin developer, I think I will leave this issue for now, and work on other things. The examples are super contrived anyways, and you are totally right.

So.. it will be released as a language with the others.

Thank you again for your time. I really and truly appreciate it.

 
Papriko
Peppery One

Papriko



  7/3/2020

Holy moly, I'm not sure if I ever wrote 7000 lines of anything! :P
But you're welcome, I'm glad that I could help at least a little bit.


Lets play plants! Photosynthesis... Photosynthesis... Photosynthesis...
 


downloads
cobs
adoptions
creaturelink
metarooms
breeds
 
gallery
art
wallpaper
screenshots
graphics
promos
sprites
dev
hack shack
script reservations
dev resources
active projects
dev forum
 
community
links
advice
chat
polls
resources
creatchi
 
forum
bookmarks
general
news
help
development
strangeo
survivor
mycaves
log in
register
lost pw
1 online
lisdude
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki