# divide input and alter results

Hiya.

What I’d try to do, preferably in glulx, is have the player input a code of let’s say twelve characters.
The game should then check each character separately and be able to handle if-conditions per character.

How can I check the character or couple of characters in a specific spot of an inputted code?

Well, naïvely all you need to do is to mask out the part of the code you don’t want:

``````To decide whether (code - a text) is valid:
if the number of characters in the code is not 12, decide no;
replace the regular expression "\W" in code with "";
if the number of characters in the code is not 12, decide no;
yes.

There is a room.

To decide which text is first block in (t - a text):
let x be text;
repeat with c running from 1 to 4:
let x be "[x][character number c in t]";
decide on x.

When play begins:
let the code be "abcdefghijkl";
if the code is valid, say first block in the code;
otherwise say "Invalid code."``````

In this case, we enter the code “abcdefghijkl”, check that it’s of valid size and only contains letters, and then pick the first four letters out of it.

The simplest way to do it is probably to use rulebooks for the various options.

``````Yourself has a number called life points.

The life option rules are a text based rulebook. The life option rules have default success.
A life option rule: rule fails.

A life option rule for "a": now the life points is 10.
A life option rule for "b": now the life points is 11.
A life option rule for "c": now the life points is 12.

When play begins:
let the code be "abcdef";
follow the life option rules for character number 1 in the code;
if rule failed, say "You have entered an incorrect code."

There is a room.``````

This is a bit less obvious, but the idea is that this code sets the “life points” (hit points, maybe). In this example, the first letter in the code determines the life points. If the code doesn’t match any of the life option rules, the rulebook returns failure and we know that someone has entered an invalid code.

I can’t make head or tails of that code… I’ll try it when I get home and hope for the best.

Any chapters in the documentation you’d recommend for this?

Yes: Chapter 19: Rulebooks and Chapter 20: Advanced Text. My advice is, don’t just try it, but step through the code and try to determine what each piece does.

That has a name. It’s called FrankenCoding. From Frankenstein’s creature (he’s not a monster. the villagers were the monsters), a composite creature. FrankenCode is code composited from various examples (with or without internal modifications).

And it’s what I do. Hence why i ask so many damn questions.

And that’s perfectly fine. Honestly, I grab a lot of solutions off of Stackoverflow myself. The thing is, I also take the time to understand why said solutions work, so I won’t have to do the same work all over again the next time I need a similar solution.

again, frankencoding
if you don’t tinker with it to make sure you understand why it ticks so you can alter it whenever you need it, you’re doing it wrong.

i’ll get back to you after i’ve cut open your code and tinkered with it.

You gotta cut up enough corpses to know how to keep them alive, Doctor.

Metaphor. Metaphor! Put the sharp thing down, Hanon.

I like this attitude.

Doctor Frank N. Stein wanted to understand life, so he stitched together the dead, time and time again, until he had enough working parts (parts he knew through research and understanding would work together, not just separately) and the right conditions (you can only know when and how that is by understanding the project FULLY) to recreate life and understand that better.

That’s real frankencoding. forget what you read when you google the term nowadays. Seems the majority of people are doing it wrong.
the original concept deals with understanding something by inspecting its parts, altering them, and putting them to work in a new project as an intricate part of a whole.

nothing quick or loose about it.

you know what you get when you slap stuff you don’t understand into your project?
Chaos.

maybe not right away - but you’re on both knees begging for things to go wrong.