CodeWalrus

Development => Web => Topic started by: _iPhoenix_ on October 15, 2018, 11:13:02 am

Title: Village
Post by: _iPhoenix_ on October 15, 2018, 11:13:02 am
So apparently I don't have a thread for my current project here. Dang.


Village is my long-term project. It's an Esolang where you are a village chief and you get to command people around and do things. It's a lot of fun.


Here's a basic "hello, world" program:
Call for the villager named Ada.
Tell Ada to write the text "Hello, World!" on her scroll.
Tell Ada to post her scroll to the Community Message Board



Pretty simple!


Villagers can have occupations.
Call for the villager named Alan.
Teach Alan how to gather wood.


Note: This next task takes 3 successful lines of code to complete.
Tell Alan to gather 20 wood.


Note: waste 3 commands.
Call for the villager named Ken.
Teach Ken how to draft blueprints.
Tell Ken to make a blueprint for a railroad to the North village.


Note: At this point, Alan's done getting wood.
Tell Alan to write the text "I have " on his scroll.
Tell Alan to write the amount of wood he has on his scroll.
Tell Alan to write the text " wood." on his scroll.
Tell Alan to post his scroll to the Community Message board.


Not all of the features are officially documented yet, with the main undocumented feature being Ask commands, aka conditionals. They are explained pretty well in my Cemetech topic:
large quote: ShowHide
QuoteSyntax: Ask [villager name] if [he/she] has [quantity] [item type].

That's a little weird, so here's an example: (Oh yeah, I added a female villager, Ada, named after Ada Lovelace)

Call for the villager named Ada.

Ask Ada if she has any stone.
- If she doesn't:
- Tell Ada to write the text "I do not have stone" on her scroll.
- If she does:
- Tell Ada to write the text "I have stone" on her scroll.
Tell Ada to post her scroll to the Community Message Board.


As you can tell, there are a few things going on here.
Call for the villager named Ada. makes Ada available for us to use. Because of my current crappy occupation-selecting script, she is an architect, but that doesn't really matter in this script.

Ask Ada if she has any stone.
This is the conditional statement. Of course, Ada does not have any stone. Only quarrymen can have stone.
The keyword any means more than one. You can also put a number in that conditional, and it will mean "greater than or equal to <number>".

Eventually, I will add the ability to use the word "exactly" before the number, but you can achieve this anyways with clever programming.

Because this is a conditional, we have to increase the indent level.

- If she doesn't:
- Tell Ada to write the text "I do not have stone" on her scroll.
- If she does:
- Tell Ada to write the text "I have stone" on her scroll.
This section of code is the conditional statement "body". The code in here is executed based on how the conditional happened.

[size=0pt]I see a rage coming from many programmers in here about what I am going to say in this section, but if you think about if statements in, say, JavaScript, the initial '{' can be viewed as a label to jump to, as can the '{' after the else.[/size]

- If she doesn't: and  - If she does:
Indent levels in village work like this:
<nothing>
-
  +
   *
    -
     +
      *
(and so on)


You don't need to memorize the pattern. If you get it wrong, the interpreter will kindly tell you which one to use.

The " -" before our command indicates that this is the first indent level. The space after the dash is a stylistic thing, it can be omitted.

The If she does: and If she doesn't: are labels that are jumped to if the condition is true or false, respectively. They can occur in any order. If there is only one of them in the conditional statement "body" and it doesn't apply, the entire conditional will be skipped.

If you run the code above, you will notice that only the text "I do not have stone" shows up on the output ("Community Message Board"). The other code beneath the If she does: label was skipped because it did not apply.

The end of any body section is always signified by a decrease in indentation.




There's more stuff in the docs (https://github.com/Legend-of-iPhoenix/Village/tree/master/docs).

Link to interpreter (https://legend-of-iphoenix.github.io/Village/)

The console messages (when debug mode is on) will help explain the examples and should help you.

Enjoy!
Title: Re: Village
Post by: _iPhoenix_ on March 17, 2019, 11:34:36 pm
Well I've forgotten to post updates here and the language has completely changed so yay. Most recent update post.


I'm thinking of picking up this project again. I finally wrote documentation for Ask (https://github.com/Legend-of-iPhoenix/Village/blob/master/docs/commands.md#ask). I'm trying to keep the documentation understandable for someone with only a marginal programming ability (i.e. may have touched a C-based programming language or similar in the past or just started.)

I'm looking for feedback on this documentation (suggestions via post, ping, or PR are welcome!)

I'm also looking for clean (as clean as you can get with this language >.>) demo programs.

You can easily relocate your input (In lieu of input commands, I'm using the "modify this program with input values" technique) to the top of the program using Skip commands. I created a trivial multiplication program here. It's a model Village program, about as clean as it gets. I'm playing with the idea of named labels at some point, so that users viewing without line numbers don't have to count. You can just load it into the interpreter (https://legend-of-iphoenix.github.io/Village/) though.

Skip to line 22.
Note: ==========
Note: Trivial multiplication program
Note: Results: A*B -> output
Note: Author: _iPhoenix_
Note: ==========

Note: Inputs:
Note: =======

Note: MODIFY THIS LINE FOR A
Tell Ada to mine 16 stone.

Note: MODIFY THIS LINE FOR B
Tell Alan to mine 16 stone.

Note: =======

Tell Ken to write the text "waiting..." on his scroll.
Skip to line 40.

Note: Init:
Note: =====

Call for the villager named Ada.
Teach Ada how to mine stone.

Call for the villager named Alan.
Teach Alan how to mine stone.

Call for the villager named Ken.
Teach Ken how to mine stone.

Call for the villager named John.
Teach John how to mine stone.

Skip to line 9.

Note: Main program:
Note: =============

Tell Ken to mine 1 stone.
Tell Ada to double her stone.

Tell Alan to write the text "waiting..." on his scroll.
Tell Alan to write the text "waiting..." on his scroll.

Tell Alan to clear his scroll.

Tell Ada to give John half of her stone.

Ask Ken if he has less stone than Alan.
- If he does:
  + Skip to line 40.

Note: Output:
Note: =======
Tell John to write the amount of stone he has on his scroll.
Tell John to post his scroll to the Community Message Board.