Page 1 of 1

A command to compare any type of value?

Posted: Mon Apr 06, 2015 1:22 pm
by Bugala

Code: Select all

a = "text"
if a = false
something
endif
This piece of code will return an error, as it should. For it is trying to compare a string with a number (false = 0).

However, sometimes it would be handy to be able to compare these things with the "equals" idea.

For example, I am right now having a variable that would be handy if i could set it to FALSE, when there is nothing there, and when there is something there, it would store the layers name.

but there come the problem of comparing. cannot check if that variable is FALSE, if there is layers name inside it.

I can easily get round this by using string name "false" instead of just FALSE, but due to syntax highlighting, it would be easier to read the code if it would read that blue False, than plain, same looking as everything else text "false".

So, first of all, is there something like result = compareany(variable1, variable2) existing, and if not;

Then add it to Hollywood wishlist.

Re: A command to compare any type of value?

Posted: Mon Apr 06, 2015 10:22 pm
by airsoftsoftwair
I think what you want is Nil.

Re: A command to compare any type of value?

Posted: Tue Apr 07, 2015 1:09 am
by Bugala
Thanks a lot. Didnt know you could compare NIL to both strings as well as numbers. I can definetily use that one as solution.

Was thinking NIL too much as a number (0) again.

Re: A command to compare any type of value?

Posted: Fri Apr 10, 2015 12:59 am
by Bugala
Seems NIL didnt work out.

Code: Select all

a = nil
if a = nil
works fine, but what i need is:

Code: Select all

mytable.a = nil
if mytable.a = nil
will tell me table field "a" was not initialized.

Re: A command to compare any type of value?

Posted: Fri Apr 10, 2015 7:03 pm
by Allanon

Code: Select all

mytable.a = nil
if mytable.a = nil
WRONG


Code: Select all

mytable.a = nil
if HaveItem(mytable, "a") ...
RIGHT (Hollywood 6 command)
;)


Code: Select all

If GetType(RawGet(mytable, "a")) = #NIL ...
RIGHT (Hollywood < 6)
:)

Re: A command to compare any type of value?

Posted: Fri Apr 10, 2015 8:07 pm
by Bugala
Ah, that is very handy command in Hollywood 6. Good to know, that will nicely solve the problem in future.

Thanks Allanon.