How do i set a value based on another value?

Twine Version:
[also choose a Story Format tag above]

I have a choice in one passage for the player to talk to a character, if they do it sets the value $askedjames using this code

(set: $AskedJames to true)

A few passages later the player is given an option to steal some bacon and will succeed depending on if they talked to james or not, i then want to set the variable $hunger to reflect if they got the bacon or not. The test code i have for this is

(if: $AskedJames,(set: $Hungry to false))[get bacon] (if: not $AskedJames,(set: $Hungry to true))[no bacon]

but i keep getting the error

1 too many values were given to the (if:) macro.

and both “get bacon” and “no bacon” showing. what am i doing wrong here?

Looks like you have your (set:) inside the parentheses of the (if:), when it should be inside the square brackets afterwards instead. The way if works is:

(if: condition)[text that's shown if condition is true](else:)[text that's shown if condition is false]

So you want:

(if: $AskedJames)[(set: $Hungry to false)]
\(else:)[(set: $Hungry to true)]

But in this case you don’t need an if command at all, I think you can just do:

(set: $Hungry to not $AskedJames)

That’s a very elegant solution. Thank you so much!