'if' object

jazzisfaction's icon

the reference says that the 'if' object also accepts symbols but I didn't succeed in using it.
i tried:

if $s1 == $s2 then 1 else 0 ----doesn't work
if $s1 == hello then bang ----doesn't work
if $s1 == 'hello' then bang ----doesn't work

i couldn't find any examples of the 'if' object using a symbol.
could anybody help me please and send some examples or tell me where my mistake is?

thanx
Cheers
Peer

Roald Baudoux's icon

It does also not work with double quotes...

jazzisfaction's icon

so is it a bug?

jvkr's icon

A bug, or the documentation department already included functionality that has not yet been realized. I tried a few things, but nothing works and there are many complaints.

_
johan

jazzisfaction's icon

ok...thanx guys....I'll find another solution ;-)

ShelLuser's icon

Its not a bug.

Check the if reference page and you'll notice (at the bottom) that operands like == are used to compare two numbers. Not symbols or lists; that's where your error comes from when trying a symbol comparison.

Also check if's message list: In left inlet: The word symbol, followed by a symbol (a word), will be stored in place of the $s argument.

Proof of concept follows below; when the number field is larger than 5 the symbol will be passed, otherwise a bang is send out.

Max Patch
Copy patch and select New From Clipboard in Max.

So what exactly are you trying to compare? Two messages or so ("dave" and "mike" for example) ? Because then you might be better of using either the zl or the regexp object.

Tj Shredder's icon

I consider "if" an obsolete object in most cases (not all). Its only there for those who are stuck in lines of code coding/thinking...;-)
Check out "zl compare"...

Stefan

frascal's icon

hello,
maybe you forget "set"

if $s1 == $s2 then set 1 else set 0

I never use whith s just whith i but i thing it's the same
P

Roman Thilenius's icon

arent symbols just a pointer to a table object.

pdelges's icon
Max Patch
Copy patch and select New From Clipboard in Max.

You're right Roman, it's like this in expr since years:

Roald Baudoux's icon

The help file should include your example, Patrick !

pdelges's icon

Roald,

not sure Roman would agree ;-)

I think the documentation is clear enough: if needs a conditional expression following expr's syntax, and expr's documentation is quite explicit about this feature, even expr.maxhelp.

Bonne fin de journée,

p

Roald Baudoux's icon

Patrick,

You're right about the principle, but it wouldn't be so difficult to integrate an example with symbols like yours in the help patch.

A bientôt.

R

jvkr's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Ah. Basically the $s can only be the first variable: $s1. Another example then.

_
johan

Emmanuel Jourdan's icon

I added an example to the help file, but I would rather consider this feature deprecated.

pdelges's icon

Hi ej,

why deprecated?

p

ShelLuser's icon

@jvkr: you do realize that the reason your 2nd example 'doesn't work' basically behaves as such because the message contents is wrong (wrong order) ?

Edit2: When you start the message with 1 the if object will consider this as a list and treat it as such (it won't iterate over the separate parts). And because it doesn't recognize the first part as a valid message it doesn't respond to it.

Just saying to make sure people don't get the idea that the construction can't work when all you're using is a message object.

...I should test more thoroughly before posting :-)

Roman Thilenius's icon

it is deprecated because there are [110.sym_==] and [110.sym_!=].

[if] is getting lovely when you need a gate in an expression.

[if (((1*((random(1,100)))
makes you one [110.probagate] with only one object.

-110

1363.110.sym_change.mxb.zip
zip
Roman Thilenius's icon

btw, think about it, what should your friend the computer do when you give him this:

[if maria > sandra && sandra >= 0 then bang else out2 bang]

see why i cant work with symbols?

it would break the paradigm because it would be limited to == and !=.

-110

Emmanuel Jourdan's icon

@Patrick It's just going to stay there as is. It's unlikely that we will changing something in this area int the future.

Roman Thilenius's icon

ok you might say [if maria > sandra then bang maria] seems right, but thats not what maxmsp is about.

-110

Roald Baudoux's icon

if (all my wished Max features == true) then (status = happyness)

pid's icon

if roman bangs maria then sandra == unhappy

Roman Thilenius's icon

in PHP 5 there is [===], which can compare type of 2 inputs as well as the
input itself - i have made a max patch which can do the same now ^^