A command to compare any type of value?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

A command to compare any type of value?

Post 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.
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: A command to compare any type of value?

Post by airsoftsoftwair »

I think what you want is Nil.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: A command to compare any type of value?

Post 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.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: A command to compare any type of value?

Post 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.
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: A command to compare any type of value?

Post 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)
:)
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: A command to compare any type of value?

Post by Bugala »

Ah, that is very handy command in Hollywood 6. Good to know, that will nicely solve the problem in future.

Thanks Allanon.
Post Reply