Accepting multiple inputs at once

Hello! Sorry if this has already been answered, but my searching didn’t turn anything up. I’m in the process of writing a four dimensional spaceship tactics game, and I’d like the player to be able to type something like “acel 0, 2, 3, 6,” and have the game take those four values, 0, 2, 3, and 6, and change four values of the player to those numbers.

How do I go about accepting multiple inputs in a single command? Thanks!

This is tricky, as far as I know. You can have an action applying to two things, but you can’t have an action applying to two non-object values (or more than two of anything).

When you are dealing with things, you can use a command like “get beaker, pipette, flask” to get them all–this puts {beaker, pipette, flask} into something called the multiple object list, and then by default runs the action (in this case the taking action) on every item of the list in turn. In theory you could use the multiple action processing rulebook (see Writing with Inform §17.20) to figure out the list the player typed and process your action, but having spent far too much time trying to mock something like this up, it appears that this would choke any time you had a repeated value in the list, so it won’t work.

Sooooo… the only thing I can think of is to make acceleration an action applying to one topic (Understand “accel [text]” as accelerating) and then use regular expressions to figure out if the text entered (“the topic understood”) is a list of four numbers. As the saying goes, now you have two problems. Sorry!

I’d suggest an Inform 6 general parsing routine. Probably faster than using regular expressions here, if you know how they work (which I don’t really).

Inform 7 can parse “accel 0.2.3.6” using a 4-dimensional unit. See chapter 15 Numbers and Equations in the manual Writing with Inform.

Thanks for all the responses, everyone!

This sounds promising. Does this work sort of like how it describes accepting heights in feet and inches? Should I be looking at this section? inform7.com/learn/man/WI_15_14.html

Actually, this looks pretty close to what I need: inform7.com/learn/man/WI_15_15.html

Is this more or less what I’d have to do? (where wa, xa, ya, and za, are the different accelerations)

An acceleration is a kind of value. 0.2.3.6 specifies an acceleration with parts wa and xa and ya and za.

I know nothing about that, lol. What exactly is it?

Yes that would work for the quoted example. When declaring the unit (acceleration), fill in the maximum values like 1.99.99.99 (the first doesn’t matter). Make sure to use the Glulx format (settings tab in Inform 7). Negative units can only be parsed in the first field e.g. -1.2.3.6, not 1.-2.3.6

You can make an action which accepts (parses) an acceleration. This example demonstrates extracting a field (ya) from an input acceleration.

[code]Accelerating is an action applying to one acceleration.
Understand “accel [an acceleration]” as accelerating.

Report accelerating:
say “You typed [ya part of the acceleration understood].”
[/code]

I think Draconis is suggesting that you could make an action which accepts any text (example below) and then write your own parsing function to convert a text like “0, 2, 3, 6” into numbers. You could use regular expressions to extract each number from the quote.

[code]Accelerating is an action applying to one topic.
Understand “accel [text]” as accelerating.

Report accelerating:
say “You typed [the topic understood].”
[/code]

Effectively, but using I6 instead of I7. A “general parsing routine” is what I7 creates when you make a custom kind of value. Since the parser already breaks the input at each comma, this would basically call the “find a number” routine, look for a comma, and repeat until it found something which was neither number nor comma.

Then in I7, you’d define your action with “accel [multiple numbers]” and the GPR would give you a list of them. This would also allow arbitrarily large values (within Glulx’s limits) for all the parts, including negative ones.

Not an elegant solution to write, but easy to use. I’ll see about writing that GPR later.

I would suggest that instead of trying to parse a command, you could build controls into your ship. Make four acceleration knobs and allow input like SET/TURN ACCELERATION DIAL A TO 5 or SET ACCEL C TO 8. Then have an “accelerate” button to carry it out.

I actually started with something like that, but it was quite a bit of fiddling, and after each action, the ship would move, which made it quite difficult to move to an intended destination. Though I guess I could have something that amounts to an end turn button, where it then updates all the values of the ship and all other objects, including movement. I think that’s likely to be the best option.

I do need it to accept negative values for any/all of them… So I’d have to somehow get it to parse the numbers like Draconis suggested.

Huh, I guess I did write something like that in C many a year ago, but I’d be curious to see how you go about that in I6. I’ve never been a terribly efficient programmer myself, lol.