divide input and alter results


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;
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. :slight_smile: 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. :slight_smile:

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?

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

Ladies and gentlemen, we have a champion crusading for his beliefs!

Teasing aside, though, I do seriously like that attitude. You have to understand how it works. When I tried to program IF myself I always shied away from extensions because of that - I’d prefer to patch it myself than use someone else’s code, which was doing something I knew nothing about. In retrospect, that was quite silly - extensions are a tool to be used, and the process of selection for inclusion in the I7 site seems rigorous enough that it won’t spring any surprises on you and the documentation and examples give you all the information you need.

…I’ve been very rambly for the past 24h. Do excuse me. Just keep on as you’re doing, that attitude will serve you well.

you know you can open extensions from inform, right?

File, Open Extension, Author, Extension - and BAM! the code! lots of studying help right there.

I gotta say I can’t make heads or tails out of most things, especially the I6 stuff, but that’s dark sorcery and I’m keeping my mitts off that.