3. Coding: Actionscript Syntax and Logic - XaderaDiddle/Nimin GitHub Wiki

Actionscript Syntax and Logic

Just like every coding language, Actionscript has it's own requirements for writing code, a syntax. Think of it like grammar rules.

String Syntax

Per "Coding Basics", strings are lines of words that are supposed to be read as a sentence, rather than as code. They require " on either end of the string. Strings are really important for a game that is all about text.

Anything within quotes will be ignored by the code as anything code-related, except when you use an "escape" character, which in Actionscript's case is a backslash, "". Having a "" in a string will make the game read the next character as code (or not code). The major ones you'll need to know are:

"\r" - This indicates a new line; the code will break up the string at the \r with a line in between. If you do \r\r, it will add 2 new lines, which is a great way to indicate breaks in paragraphs.

Example:

"This string in the code.\r\rLooks like 2 paragraphs."

Looks like this in the output:

This string in the code.
  
Looks like 2 paragraphs.

"\"" - This makes the " in the middle of a string be read as part of the string, rather than the encapsulation of the string itself.

Example:

"This person says \"I'm saying a thing!\""

Will look like:

This person says "I'm saying a thing!"

Otherwise, this:

"This person says "I'm saying a thing!""

Will result in errors because it tried to read (I'm saying a thing!) as code, instead of being part of the string. Also notice how all the " specified are straight. Some text editors add "fancy" quotes that curl them a little based on the start and the end. DO NOT USE THOSE. They have extra data to them that the code doesn't read well.

You can also add strings together. You literally add them.

"This is string 1." + " This is string 2."

Results in:

This is string 1. This is string 2.

First notice how the extra space in " This is string 2." was put in. The game doesn't automatically know normal grammar, you have to make sure to account for it yourself. Same thing goes for using \r\r; if you want a paragraph, even when you're adding strings, you need to be sure to add in the \r\r yourself.

The reason you want to add strings together is so you can vary what the string reads. One way is to call a function that sends you back a string.

"I have a "+buttDesc()+" butt."

buttDesc() is a function that gives you an adjective based on the size of the character's butt. You have no idea what the adjective is, since it can be all sorts of words, but they're all set up to be an adjective. You just have to add it into the string you're putting out. The above would look like:

I have a big butt.

Or

I have a gargantuan butt.

You need to make sure you build the sentence around it to work. "butt" is not provided naturally, so you'll need to put that in yourself. This is to ensure that the nouns in sentences are written according to normal writing standards, such as diversification to make the text less boring. You'll need to say "ass" or "booty" or "buttocks" on your own. The only thing the function provides is the description of said donk.

The other way adding strings together helps is for using logic to build a string based on certain variables. Nimin is built with this in mind and has it set up to make it easier. Rather than trying to track a string and keep adding to it, you can use textL("your string") to start a new string for the main window to display, and textLP("more stuff to add to your string") to add to the string that is in the window, just like using a +.

General coding syntax

In Actionscript, there's a couple basics you need to make sure you do, or else the code breaks. If you look at the code, you'll catch on pretty quickly, but the 2 main ones are:

; - Every line of coded needs to be "finished" with a ";". If you don't, the code assumes you're starting a block or something, and continues to "wait", even if nothing comes, and eventually errors. Thing of it like needing to say "Over" when talking on a radio; you need to say "Over" when you're done speaking so the other person knows when you've stopped.

{ } - Curly braces indicate a "block". A "block" is several lines of code that is only performed if the block is entered for some reason, whether it be a function, an "if" statement, a loop, etc. You put the { before the code you want to execute, and the } when the code is finished. This separates out code so only chunks are performed at a time; otherwise the application will just keep doing everything from top to bottom. As you can see in the code, it is nice to add an extra tab within a block to help keep track of how "deep" you are, as you can have blocks within blocks and all the {} can get hard to track.

Logic Syntax

Logic is necessary for diversifying your event based on different variables. Want to make sure "thing 1" is said if the character is over 60 inches tall, otherwise only say "thing 2"? Logic! And it's written fairly similarly, using blocks and logic.

if (tallness > 120) {
  textL("You are tall!");
}
else if (tallness > 60 ) {
  textL("You are kinda tall!");
else {
  textL("You are short!");
}

The above acts as it reads. If the "tallness" variable is greater than 120, then say "You are tall!". If you're not greater than 120, but if you are greater than 60 (else if), then say "You are kinda tall!". If you don't meet any of those (else), then say "You are short!").

I'm sure you can see how helpful it is to have different sentences based on different variables. But here's other syntax that is necessary for logic (if you aren't familiar with basic logic, please consult google).

&& - "And". Both sides of the && need to be true in order for the block to be entered.

if (tallness > 120 && cockSize < 4) { textL("Your penis looks tiny on your tall body!") }

You need to be taller than 120 AND have a cock size less than 4 to see the sentence "Your penis looks tiny on your tall body!".

|| - "Or". Only one side of the || needs to be true in order for the block to be entered.

if (tallness > 120 || cockSize > 20) { textL("I'm not sure if I can fit you!") }

You need to be taller than 120 OR have a cock size greater than 20 to see the sentence "I'm not sure if I can fit you!" (you can make up the context there :P ).

! - "Not". This reverses the true/false of whatever follows it. Don't bother using it unless you know how logic works, and even then it won't likely come up often.

Otherwise, Actionscript logic (and coding logic in general) functions like normal logic. You can string && and || into the same logic, with parenthesis making subgroups and whatnot. If you need help figuring out the logic needed for a complicated scenario, look it up, or ask.