In some scripting languages, you can do things like
if !(Variable = 0), then
Anything like this in Sugarcane? I'm looking for something that would let me write a condition if this string is not zero characters. I can't ask whether the string is greater than 0, because, if I'm not mistaken, you can't compare a string to a number or another string. You can't compare strings to anything. Right?
Why does it matter? Well, in my story I have Large weapons (swords, epees etc.) and Small weapons (daggers, knives, particular kinds of knives etc.). So a sword, for example, has to answer to two kinds of checks: as a Large weapon (for frisking) and as the actual weapon that it is, for damage and so on. These things overlap, but not completely. Every sword is a Large weapon, but not every Large weapon does sword damage. And contrariwise.
So if I want to give the player a sword, I must set two variables every time, like so:
<<set $hasLargeweapon to 1>>
<<set $Largeweaponis to "sword">>
(Or do a long list of conditionals for every Large weapon in the status panel that's <<display>>ed down every passage. The conditionals would set $hasLargeweapon to 1 whenever a weapon from the list was picked up or put down. That can work, but it requires updating the list whenever I want to introduce a new weapon. Hmm.)
Now, other than the workaround I just gave, it's always two variables that have to be set. I can then run checks on what $Largeweaponis gives me: <<if $Largeweaponis eq "sword">>... do 5 damage. And the first check takes care of the weapon category. But it would be so much better to be able to ask
is the string $Largeweaponis longer than zero characters?
That way I wouldn't need the $hasLargeweapon at all, and I could invent new Large weapons on the fly (a timber log? Think about how easy it would be to create, say, a list of general offenses - not just items but actions, all checking for the non-emptiness of a couple of strings). Any length of the $Largeweaponis string would be enough to show that the player is carrying a Large weapon, in addition to the primary job of specifying what the weapon is. It would cut the work in half, no pun intended. And when the player throws down his sword (or any Large weapon), I would just <<set $Largeweaponis to "">> for those frisking checks.
Of course, I can check for "" already, if I want an empty string. But a) "" is not 0, which I could work with; b) I want to detect a non-empty string - probably via negation, to the effect of << if $Largeweaponis is not "">>. But it has to include the condition that the data, in addition to not being an empty string, is not any number either, in case I do want to stick a number there for some reason. And because value 0 means unarmed.
Just thinking out loud here: maybe I could ride an error? If I try to do a number-only operation on a string, that's going to throw me a 0, right? And I can put an "equals" condition to that.
<<set $lifeordeath to $Largeweaponis / 5>> this should give a 0 - no?
<<if $lifeordeath eq 0>>... then the player is carrying a Large weapon. The trick is to set $Largeweaponis to a number other than 0 when the player put away the weapon. So I now only need to
<<set $Largeweaponis to 5>> when he puts a Large weapon away
Then just set the string to the weapon name, when picked up, no matter what kind
<<if $lifeordeath eq 0>> would be the universal check for Large weapons
What do you think? Will this work, if there is no ! operation?
---
Update: just realized the player would see "you are carrying a 5" when unarmed. But that can be solved through the panel, where health and so on are shown. Like so:
<<display "Status bar">>
And in the Status bar passage:
<<if $lifeordeath eq 5>><<print "You are unarmed">><<else>><<print "You are carrying a " + $Largeweaponis>><<endif>>
Comments
I'm quite sure you can write <<if $largeweapon gt 0>>.
Or maybe if I could mark up the strings somehow, you know. Like put a detectable but invisible character in the strings? You know, <<set $Weaponis to "daggerS">> or <<set $Weaponis to "swordL">>. The player wouldn't see L and X, but the if condition would, looking at the strings. Anything like that existing?
That works if $largeweapon is set to a number, but a string? I tried this: Gives a 0. It means you can't compare a number and a string (this string is longer than zero characters and, well, just bigger than 0 in every way. ) But you can compare string length, apparently, with the < and >, or gt and lt, which I assume work the same way. The documentation article on expressions says strings can only be added.
A very simple example:
note: The following examples have not been tested, so the syntax may not be correct.
You could use a variable to represent each of your items: You could use an array of objects, where each element represents a items: You may want to look at my answer to your list based question