0 votes
by (120 points)
Hello. I am very new to both Twine 2 and coding in general. Like... picked it up a day ago. Trying to create a simple adventure game with the program and have run into a problem with combat. I found a guide online to shows you how to set up a simple 50/50 combat system, but seems to be out of date or something and I have not been able to find another guide.

 

Problem is as follows: Followed the guide to set this up, and the first part works for being attacked. Without the second part it runs perfectly. It's once I get to the (else:) for the 50/50 chance that I get an error. This is what I have written below, and any help would be appreciated.

 

(if: (either: 0, 1) is 0)[
The giant rat leaps up and bites you!]
   (set: $hp to $hp - (either: 1,2,3))  
   (if: $hp < 1)[ You have been [[defeated by the giant rat]]! ]  
   (else:)[ Your health is $hp.
   [[Fight the giant rat!]]
 ]
 (else:)[ You slash the giant rat with your sword!]  
   (set:$monster_hp = $monster_hp - 1, 2)  
   (if: $monster_hp < 1)[ [[You have killed the giant rat]]! ]  
   (else:)[    
     Its health is $rat_hp.
    [[Fight the giant rat!]]
 ]

 

The problem I get with the second part, past the (else:) after the break, is I get an error telling me: (set:)'s 2nd value is the number 2, but should be a 'to' or 'into' expression.â–ºThe (set:) macro must only be given a 'to' or 'into' expression.

 

And another problem is this supposed to run both outcomes at the same time? I'm really over my head and just trying to get something simple done to work up a bit of know how... but this is frustrating me beyond belief. Any help would be greatly appreciated... and remember, really knew so don't know a lot; especially when it comes to jargon.

2 Answers

0 votes
by (23.6k points)

Did you maybe mean to write:

 

(set:$monster_hp to $monster_hp - (either: 1, 2))   

 

0 votes
by (159k points)

I suggest you don't include underscores in your story variable names, because that character is generally used to indicate a temporary variable. I also suggest being consistent in which operator you use when you assign a value to a variable, I personally would use the to operator because it is easy to confuse a single equals sign = operator with a double equals sign == operator and one means assignment where the other means comparison.

Besides the issue pointed out by @idling I believe you are also placing some of the close square brackets of your associated hooks in the wrong places, I believe the following code is what you were trying to write.

(if: (either: 0, 1) is 0)[
	The giant rat leaps up and bites you!

	(set: $hp to $hp - (either: 1,2,3))

	(if: $hp < 1)[
		You have been [[defeated by the giant rat]]!
	]
	(else:)[
		Your health is $hp.
		[[Fight the giant rat!]] 
	]
]
(else:)[
	You slash the giant rat with your sword!

	(set: $monsterHP to $monsterHP - (either: 1, 2))

	(if: $monsterHP < 1)[
		[[You have killed the giant rat]]!
	]
	(else:)[
		Its health is $ratHP.
		[[Fight the giant rat!]]
	]
]

notes:
a. The above code has been formatted using line-breaks and indentation so that it is easier to see the structure, most if those line-breaks and the indentation can be safely removed.
b. The above code has not been tested, it may contain syntax errors.

...