How can i make an if statement comparing text?

I dunno how much that makes sense, but I’m trying to check if two variables are not the same but both are text.

So say class = “warrior” and class2 = “puppetmaster”
what i have is *if(class != class2) but that doesn’t seem to be working.

I hope i made that clear enough :stuck_out_tongue:

Do you need a space after *if, maybe?

Nope, that part works fine.
I tried stuff like

*if(class !- class2)
*if(!{class} != !{class2})

and still wont work

I got something similar to work:

*create class "dormouse"
*create class2 "march hare"
Are you the Mad Hatter? No? Well, perhaps you're the March Hare.
*fake_choice
  #No, I'm the Dormouse.
    *set class2 "dormouse"
  #Yes, I'm the March Hare.
*if (class = class2)
  *goto irrelevant
*if (class != class2)
  *goto relevant
*label irrelevant
The classes are equal!
*goto end
*label relevant
The classes are unequal, I say!
*goto end
*label end
*ending

That works correctly. Have you tried putting a space between the f and the parenthesis? So instead of

*if(class != class2)

it would read

*if (class != class2)

It works like that with the rest of my if statements, and when i tried it it didn’t make a difference

Stand-alone *if statements also work. And “” is just for the string value, not for the variable name itself.

@AnomanderRake Can you post the exact code? Maybe that would help.

*if(class = "Illusionist")
	*choice 
		#Trap him in an illusion 
			*goto cultistfight 
			
		#Trap him in an illusion 2
			*goto cultistfight 
*else 
	*choice
		*if(puppetLion) 
			#Have your puppet lion do whatever
				*goto cultistfight 
		
		*elseif(puppetCobra)
			#Have your puppet cobra do whatever 
				*goto cultistfight
			
		*else
			#Have your puppet rat do whatever
				*goto cultistfight 
			
*if(class != class2)
	*if(class2 = "stealth")
		*choice 
			#Strike at the cultist from the shadows 
				*goto cultistfight

So class and class2 can be the same, and if they are I don’t want the second bit showing up because It’d be redundant. I don’t want to put the first bit inside an if statement though because that’s a lot of text, though i guess i might have to?

@Eiwynn I just downloaded a fresh copy of ChoiceScript and tried stand-alone *if and it worked for me…

And don’t apologise! Always good when people try to help. I’ve suggested plenty of wrong solutions; the important thing is getting at the problem eventually. (:

@AnomanderRake Can you select your whole portion of game text, and then click on the button that looks like </> so it’ll preserve your spacing? That way it’d be easier to figure out what’s going on.

Edit: I noticed a few problems with indentation. After *if statements, *choice, and *else, you need to always indent by one level. Try this?

*if(class = "Illusionist")
	*choice
		#Trap him in an illusion
			*goto cultistfight

		#Trap him in an illusion 2
			*goto cultistfight

*else
	*choice
		*if(puppetLion)
			#Have your puppet lion do whatever
				*goto cultistfight

		*if(puppetCobra)
			#Have your puppet cobra do whatever 
				*goto cultistfight

		*if ((puppetLion = false) and (puppetCobra = false))
			#Have your puppet rat do whatever
				*goto cultistfight

*if(class != class2)
	(what? there's nothing here)
*if(class2 = "stealth")
	*choice
		#Strike at the cultist from the shadows
			*goto cultistfight

Or, is this meant to be one choice and you only see certain options? Then you only need one *choice command. I could do it up as an example that way if it’d be helpful.

1 Like

It is all supposed to be one choice, it’s a bit of a mess :stuck_out_tongue:
But *if(class = “stealth”) is supposed to be inside the class != class2 statement.

*choice
	*if(class = "Illusionist")
		#Trap him in an illusion 
			*goto cultistfight 
			
		#Trap him in an illusion 2
			*goto cultistfight 
         *elseif(class = "Puppetmaster")
		*if(puppetLion) 
			#Have your puppet lion do whatever
				*goto cultistfight 
		
		*elseif(puppetCobra)
			#Have your puppet cobra do whatever 
				*goto cultistfight
			
		*else
			#Have your puppet rat do whatever
				*goto cultistfight 

	*elseif(class != class2)
		*if(class2 = "stealth")
			#Strike at the cultist from the shadows 
				*goto cultistfight

Is that any better? I still doesn’t seem to work though

Right. A choice is one unit, so to make individual options appear or not appear you don’t need extra *choices; instead it’s done with *if statements (or selectable_if, should you want an option to show but be greyed out.) And each option needs to be given its conditions separately, if I recall correctly.

I’m sure this isn’t the only way to do it, but here’s one suggestion you could try, I think:


*choice
	*if(class = "Illusionist")
		#Trap him in an illusion
			*goto cultistfight
	*if(class = "Illusionist")
		#Trap him in an illusion 2
			*goto cultistfight
	*if(puppetLion)
		#Have your puppet lion do whatever
			*goto cultistfight
	*if(puppetCobra)
		#Have your puppet cobra do whatever 
			*goto cultistfight
	*if ((puppetLion = false) and (puppetCobra = false))
			#Have your puppet rat do whatever
				*goto cultistfight
	*if ((class != class2) and (class2 = "stealth"))
		#Strike at the cultist from the shadows
			*goto cultistfight

Would that work?

Also, just a thought…in the current form, it seems like this choice, as is, will have a lot of players who only see one option (in which case, it’s not much of a choice, right?). It might be worth considering if a player will have at least two or three options available to them. If not, particularly if you’re planning on hiding additional options rather than greying them out, it might make more sense to redirect according to a player’s class instead of offering a one-option choice.

3 Likes

If it’s not working, you could potentially get around it by using a different *if choice for each option (Don’t know why my spaces aren’t working but you get the idea)
ie:

*if ((class != “stealth”) and (class2 = “stealth”))

*choice 
	#Strike at the cultist from the shadows 
		*goto cultistfight

Edit: others beat me to it :slight_smile:

2 Likes

I haven’t fleshed out the options yet there’s only one choice right now.

1 Like

Right, I see.

Also, regarding *if / *elseif / *else: they aren’t meant for choices and options; they’re for redirecting. You’ll see them used in a series with *goto, like the example towards the end of this page of the ChoiceScript wiki.

Is there a selectable_if option that hides instead of just greying out then? Maybe i’m just blind but i don’t see one :stuck_out_tongue:

The *if will hide the options for you. *selectable_if is if you want them to appear but be greyed out.

So what do you mean by if statements aren’t meant for choices and options then? What else do i use?

also,

	*elseif((class != class2) and (class2 = "Stealth"))
		#Strike at the cultist from the shadows 
			*goto cultistfight

doesn’t work either

*if on its own works with choices and options.

*if, *elseif, and *else is meant for redirection according to a stat, or to allow a player to see only one of a variety of texts according to their stats.

So an example, with *if used in choices and *elseif used to show flavour text and then redirect to a *label would be:

*create character "dormouse"

Which seat do you take?
*choice
  *if character = "dormouse"
    #I take the dormouse's seat, of course!
      *goto sweets
  *if character = "march hare"
    #I take the march hare's seat, of course!
      *goto sweets
  *if character = "mad hatter"
    #I take the mad hatter's seat, of course!
      *goto sweets
*label sweets
You are served with your favourite, 
*if (character = "dormouse")
  savoury cheese!
  *goto theend
*elseif (character = "march hare")
  carrot cake!
  *goto theend
*else
  hat-shaped biscuits!
  *goto theend

*label theend

And in your example, it’d need to be *if and not *elseif because it’s used with an option.

3 Likes

oohhhh, i see. Plus it fixed it. lol, thank you so much :stuck_out_tongue:

1 Like

Just did a quick scan, but it looks like you were inconsistent on your capitalization. String variables are case sensitive, i.e.:

*set foo "bar"
*if foo = "bar"
  This is true.
*if foo = "Bar"
  This is false.
2 Likes