Jump to content

Expressions Seem To Be A Bit Kooky


Recommended Posts

I wanted some commands to be executed when my hip file starts up.

So I created a variable "testvar" for my hip file in "Aliases and Variables" and set its value to false.

In expressions I added a function but needed to do this to get it to work:

float
testForOtls(string testVal)
{
    #run("message " + testVal);
    #run("message " + index(testVal, "true"));
    if (index(testVal, "true"))    
    {
       #run("message inside if");
       run('set testvar = "true"');
       #run("message" +  testVal);  
       run("$HIP/doStuff.cmd");    
    }

   return 0;
}

I created a null and called the function from one of its translate chanels.

Now it seems to me as though this if statement should keep getting executed because testvar will always true but it doesn't.

When the value of testvar is false index(testVal, "true") returns -1 as expected but this is the condition thats the if condition will evaluate as true. I would have thought that a -1 value would be false and 0 would be true.

So I have to test if the value is "true" and if it is then it must be false! :huh:

Is the way its supposed to work or have I missed something?

Oh Yeah. And now when I start this hip file I get the message "Empty Function". Anyone seen that before?

Link to comment
Share on other sites

Not sure if I follow you exactly. But by testing for the string "true" in the string "true" with the idex function you will return 0 when it is found because index returns the position of the test string, and -1 when it isn't found, ie when you are looking for the word "false" in the word "true". In "if" statements 0 is false and 1 is true, so you aren't really getting the two values you want doing things this way. Of course you could just add 1 to your index function, but why not just do

if ("$testVal" == "true" )

wouldn't that be simpler?

Two other things, you seem to be forgetting the $ sign in front of testVal when you are referencing it. And by using set instead of set -g or setenv you are only setting testVal for the duration of the hip file being open, which may be what you want I don't know. Setenv or set -g will make the value perminent in the file.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...