cromagnon Posted May 28, 2005 Share Posted May 28, 2005 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! 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? Quote Link to comment Share on other sites More sharing options...
sibarrick Posted May 30, 2005 Share Posted May 30, 2005 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. Quote Link to comment Share on other sites More sharing options...
cromagnon Posted May 31, 2005 Author Share Posted May 31, 2005 Great. Thanks. I thought I must have been doing something silly since noone else has had this issue. I tried using "==" but it always evaluated as true but I'm sure thats got something to do with my $ sign usage. Thanks again. Dave Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.