Some basic questions on coding

Hello, my name is Kory Toombs. I’m a game developer whose used RPG Maker, Visual Novel Maker, Pixel Game Maker MV, Solarus, and Ren’Py.

I’ve been trying to follow some tutorials on Youtube, but got into a bit of an issue trying to figure out how to give an item I’ve picked up to someone, then for something else to happen after that. I pretty much want things to happen if variables are true or false.

Some of the code I’m using =

Havejellyfish is a truth state that varies. Havejellyfish is false.

After taking the jellyfish:
if Havejellyfish is false:
now Havejellyfish is true;
continue the action;

an orange cat sleeping on the sidewalk is an animal in Wharf. The description of an orange cat sleeping on the sidewalk is “I kneel down and take a look at the cat. It’s an older cat that has lived most of its life on the docks. The give the cat a pat on the head, but it just yawns lazily without a care in the world. The cat obviously wont be interesting to play with.”


I want to be able to change the description of what happens with the cat if I give it the jellyfish.

is there a way to do a if or else statement?

if Havejellyfish is false:
an orange cat sleeping on the sidewalk is an animal in Wharf. The description of an orange cat sleeping on the sidewalk is “I kneel down and take a look at the cat. It’s an older cat that has lived most of its life on the docks. The give the cat a pat on the head, but it just yawns lazily without a care in the world. The cat obviously wont be interesting to play with.”

else???

You can’t put if/else conditions on the “top level” definitions in the code. However, you can put a condition within the description string:

an orange cat sleeping on the sidewalk is an animal in Wharf.
The description of an orange cat sleeping on the sidewalk is "[if Havejellyfish is false]I kneel down and take a look at the cat....[otherwise](Description to appear when havejellyfish is true)[end if]"

A few more notes/recommendations that may or may not apply depending on the context of the code:

  • If you just want to check whether the player is currently carrying the jellyfish, you don’t need to introduce a global variable for that: use if the player is carrying the jellyfish.
  • As it stands, the name of the cat is “an orange cat sleeping on the sidewalk”. This reads nicely in the auto-generated room description: “You can also see an orange cat sleeping on the sidewalk here.” However, the game will understand every word of that name as referring to the cat, allowing the player to type “examine sidewalk” and getting the description of the cat. If you want to customize how the cat is described in the room description, use the “initial appearance” property: an orange cat is an animal in Wharf. The initial appearance is "An orange cat is sleeping on the sidewalk."
  • Once you create an object, you can set a bunch of properties without having to name the object every time. Inform will assume that you mean the most recently created object.

All in all, you might write:

An orange cat is an animal in the wharf.
The initial appearance is "An orange cat is sleeping on the sidewalk."
The description is "[if the player is carrying the jellyfish]Cat interested in fish[otherwise]Cat not interested[end if]."

I’d recommend you at least skim over the first few chapters of the documentation (“Writing with Inform”), which go over how to create the map, how to place and move objects, how to use text substitutions, and other basic features (many of which can be a bit weird if you’re used to more traditional programming languages).

4 Likes

Hi Kory – welcome!

The good news is that most of this is pretty easy. First, you don’t need to construct your own variable to track whether the player has the jellyfish – Inform has a lot of built-in tools to make this kind of stuff easy. Similarly, modifying descriptions is simple too. You can use full if/else statements, but you can also just build conditionals into the description. This code should work:

The description of the orange cat is "I kneel down and take a look at the cat.  It's an older cat that has lived most of its life on the docks.[if the cat has the jellyfish]  It's currently toying with a jellyfish."

Writing with Inform has lots of documentation on this since obviously in interactive fiction, varying text is a big deal, but this section’s probably a good place to start.

(Note that even if the formal name of the cat is “an orange cat sleeping on the sidewalk”, in most cases you can just call it “orange cat” and the compiler will understand).

To make this work, you will need to allow the player to give the jellyfish to the cat. That’s a bit more of an advanced topic since you’ll need to understand a little bit about how actions work. This section of the Recipe Book gives some examples of ways to implement giving that you could probably just paste right in, but it might be helpful to first brush up on some of the basics of actions in this chapter of Writing with Inform if you haven’t yet checked those pieces out.

Hope this is helpful!

2 Likes

Thanks to both replies. I got a much better layout now.

The block giving rule is not listed in the check giving it to rules.

cat is an animal in Wharf. The initial appearance is “An orange cat is sleeping on the sidewalk.” The description of a cat is "[if the player is carrying the jellyfish]The cat starts sniffing the air. I bring the jellyfish closer to the cat’s nose. I wonder if I should let the cat have this?

(Try typing give cat jellyfish.)[otherwise]I kneel down and take a look at the cat. It’s an older cat that has lived most of its life on the docks. The give the cat a pat on the head, but it just yawns lazily without a care in the world. The cat obviously wont be interesting to play with[end if]."

Though I’m not sure why I can’t use the command

After giving jellyfish:

it works with taking.

The action Inform understands is actually “giving it to”, not just “giving” – that is, it’s an object that requires both a direct and an indirect object. If you try writing “After giving the jellyfish to the cat” it should work! (You could also write a rule “After giving something to the cat” or “After giving the jellyfish to someone” – rules can be specific or more general).

1 Like

Wow, I tried searching the database for words I should use. And thought take/taking should be give/giving. Thanks. This helps me continue the story into the next section.