Pushing a button once with variable outcomes

Hi all,

Very new at Inform 7 but have lots of programming experience in the past. I know this is probably an easy question but I’ve been reading the docs and searching online without finding what I need.

I’ve been trying to implement a button that behaves differently depending on circumstances- a single use button that behaves one way if X has happened, another way if X has not happened, and doesn’t do anything after the first push.

I’ve been trying a mix of “if” and “instead” statements but can’t get it straight. I want an item “nozzle” to be in the “tank” to properly dispense gas. Also, the gas needs to be paid for first before anything happens.

Desired outcomes:

Do nothing and tell you to pay if you haven’t
Spray gas on ground if the nozzle is not in the tank
Only dispense gas once, nothing on further button pushes

I’m used to being able to code “if x=true and y=true then z”, but Inform doesn’t seem to allow compound statements like this. I feel like there must be something obvious I’m missing here.

I need a construct for:

if (paid==true and buttonAlreadyPressed==false) then 
    if nozzleInTank==true
       dispense gas
       buttonAlreadyPressed=true
    else
       spray gas on ground
       end finally
else if buttonAlreadyPressed==false
    do nothing and tell you to pay
else
    do nothing

Any tips or pointers to the right reading material?

Whew, finally got it. Been a problem since yesterday. A handful of insteads with an if / otherwise if / inside one of them. I’m used to the “if” statements coming first, not “instead”.

Having past experience with both C-style coding and I7, I understand how baffling and at times frustrating the transition can be. The greatest annoyance, though, often stems from the fact that I7 uses a different idiom to accomplish various things. Working in line with that idiom will solve many of the issues you’re going to encounter.

Instead, for instance, isn’t analogous to if; Instead is a rulebook whereas the if statement is a control structure, and that’s a huge difference in I7. I remember being skeptical of rules at first, but they really can accomplish some clever things if used correctly.

If you’re more comfortable with code in this format, you may want to try TADS 3 or Inform 6.

Hope this helps.

There’s a guide aimed at programmers for Inform 7, link in my sig. Don’t know if it’ll help you or not.

Thanks all for the replies. I’m learning slowly, it’s a bit of a departure from the languages I’m used to but I’m enjoying the Inform 7 software and format. Put a week into this so far so I’ll stick with it for now. I can see already I’m over-using “instead” and need to figure out the rulebook thing a bit more.

Ron thanks, I have your guide, that and the built in help have been useful. I think I should spend some time reading existing code. A lot of things that have stumped me are pretty simple and I’m sure I’ll have some more questions.

Yeah, you definitely need a decent grasp of rulebooks to do anything but the most basic stuff in I7 – that’s where it all happens. It may not be a bad idea actually to read through the Standard Rules to understand the default workings of Inform games: there is an official, commented version of it here <http://inform7.com/sources/src/stdrules/Woven/index.html>; also , the Rules Chart <http://inform7.com/learn/documents/Rules%20Chart.pdf> provides a useful graphical overview of the order in which standard rulebooks are processed.

Very helpful, thanks!