How do I get an integer off the command line?

It seems I need to convert a string to an integer, or to read it in originally as an integer. Can’t figure how to do it…

DefineLiteralAction(Zip)
     execAction()
     {
        mainReport('Okay, Zipping. ');
        Z_ing.n = getLiteral();                 //<----  the offending line; I get a runtime error
        Z_ing.dinky2;
     }
;


VerbRule(Zip)
     'zip' singleLiteral
     : ZipAction
     verbPhrase = 'zip/zipping (what)'
;

Conrad.

Hey, I got this one!

toInteger() is my new friend…

C.

However, I’ll trade that one off for this one–

(I know, I’m always asking questions. BUT, I’m making progress!)

VerbRule(Zip) 'zip' singleLiteral : ZipAction verbPhrase = 'zip/zipping (HowManyTurns)' ;

How do I do this to get proper spaces in between words WITHOUT having them scrambled in some peculiar fashion?

–isn’t terrible. The alternatives are…

…with…

verbPhrase = 'zip/zipping (many turns how)'

Or

…with…

     verbPhrase = 'zip/zipping (how) (many turns)'

Or

…with…

     verbPhrase = 'zip/zipping (turns how many)'

Or

…with…

     verbPhrase = 'zip/zipping turns (many how)'

Or other even less likely things.

In general the problem is that TADS wants to say

THREE do you want to verb ONE TWO?

…you can tinker with the order, some, but you can’t, that I’ve seen, get to a

WORD WORD WORD do you want to verb?

–whether it’s ONE TWO THREE, THREE TWO ONE, or any other sequence.

Is there some other format I might use? Is it possible to start fresh with a string, ‘How many turns do you want to zip?’ that I can have TADS ask?

Conrad.

I don’t know the best way, but this seems to work.

DefineLiteralAction(Zip)
	whatObj(which) {
		return 'how many turns';
	}
	execAction() {
		// ...
	}
	actionTime = 0
;

VerbRule(Zip)
	'zip' singleLiteral
	:ZipAction
	verbPhrase = 'zip/zipping (what)'
;

Yes, that works!

Thanks again, Ben!

Conrad.

You should probably use singleNumber instead of singleLiteral. You can then get the value as an integer with numMatch.getval(). As a bonus, this allows stuff like:

>zap seven turns

Which is quite l33t :mrgreen:

Anyway, I didn’t look at your whole attempt (scripted waiting and all that), but I think what you want here is to extend WaitAction with a new form that also takes a number. So that in addition to the default form:

>Z [or WAIT]
Time passes...

You will also have:

>Z 10 [or WAIT 10]
10 turns worth of time pass...

Something like:

DefineIAction(WaitTurns)
     execAction()
     {
        "<<numMatch.getval()>> turns worth of time pass... ";
        // ...
     }
;

VerbRule(WaitTurns)
     ('wait' | 'z') singleNumber ( | 'turn' | 'turns')
     : WaitTurnsAction
     verbPhrase = 'wait/waiting (a number of turns)'
;

Yeah… I was considering something like that, as being better in every way, but dreaded tinkering with basic TADS verbs at that level.

However, I will be brave and face it (especially since you seem to’ve done all the work). But I’ll look to it later.

I want to get some momentum going along other lines right now, rather than nicening this up beyond functionality.

Conrad.

Whenever you define new grammar, you’re not tinkering with an existing action, you’re creating an entirely new action. For instance:

DefineTAction(WaitFor); VerbRule(WaitFor) ('wait' | 'z') 'for' singleDobj : WaitForAction verbPhrase = 'wait/waiting (for what)' ;
This doesn’t affect the library’s existing Wait action in any way. At least, I hope it doesn’t, because I do this sort of thing a fair amount, and I’ve never noticed any untoward side effects.

That’s correct. It’s a totally new Action object. The worst thing that can happen is a conflicting verb rule, but that’s rather easy to spot.

Oh God… I just got this code stable… I need a week of not looking at it before I screw with it any more…

C.