#abort(help)

1 messages · Page 1 of 1 (latest)

worldly eagle
#

I've got a macro that works as lons as it can find a particular token, but it doesn't work if it can't (at least because of a variable.)

#

So I thought I'd try abort().

#
[h:Twilight_Cleric=0]
[if(findToken("Caelum")!=""):Twilight_Cleric="Caelum"]
[if(findToken("Avatar of Ermis")!=""):Twilight_Cleric="Avatar of Ermis"]

[h:abort(Twilight_Cleric)]
#

That's what I came up with, and it works, if it can't find the token, but now I get an error if it can.

#

If I remove [Twilight_Cleric=0] and [abort(Twilight_Cleric)] that's when it works when it can find the token.

median nexus
#

@worldly eagle IIRC, abort() terminates the macro when it's true, which MTscript defines as non-zero and/or non-empty string. You say it works if it can't find the token (because the abort() doesn't terminate in that case), but if it can find the token it does the wrong thing (by aborting). But those are contradictory — you're saying that the code should continue in both cases!? So why do you want to abort at all? Maybe you're actually looking for a different operation? Or perhaps the goal isn't clear?

worldly eagle
#

When I don't have abort() in there it works when it can find the token but not when it can't.

#

When abort() is in there it works when it can't find the token, but it doesn't work when it can.

#

Which is to say that the abort() does its job of halting the macro when it can't find the token, but gives the error when it can find the token.

#

Does non-zero have to be an integer?

quiet tide
#

abort(number(thing))

crystal adder
#
[h: Twilight_Cleric = ""]
[h, if(findToken("Caelum") != ""): Twilight_Cleric = "Caelum"]
[h, if(findToken("Avatar of Ermis") != ""): Twilight_Cleric = "Avatar of Ermis"]

[h: abort(Twilight_Cleric != "")]

You need the read assert, abort, and return as "make sure the statement is true, otherwise do what the function says".
So in this case it is "make sure Twilight_Cleric is not "", otherwise abort."

quiet tide
#

Number converts “” to 0

#

Better would be [abort(ne(Twilight_Cleric, ""))]

crystal adder
#

I think I'm missing something.
If the goal is to check for strings, why not stay within that context with "" for false and use the check Twilight_Cleric != "" ? I don't see why you would want to involve number() for conversions which might not be obvious to a future reader of the code. You don't need the number 0 for a calculation here.

quiet tide
#

The question is about abort() which needs a value it can interpret as a Boolean.

#

Safest to feed it a Boolean, next best thing is a number.

worldly eagle
#

Thanks all. It works now. I haven't checked the new wiki yet. I was going off of the info in the temp wiki, and it didn't show anything other than just the variable in the parentheses.

#

I've been working on this same macro for days, and it barely even does anything.

#

Literally all it does is stop me from having to hit my own macro.