1. #1
    Member Follow User Gallery
    Join Date
    Sep 2006
    Location
    Santa Monica, CA
    Posts
    88

    Default Simple == Comparison is Failing??

    Anyone have any issues in 4R8 with comparisons?

    For the life of me, I can't figure out why a basic comparison is failing. My XYZ Size is 2, and this code should be printing "It's a match" and it's not for some reason.

    [VarSet, gTempNumber, 0]
    [VarSet, gTempNumber, [IGet, Tool:Size:XYZ Size]]
    [Note, #gTempNumber]
    [If, #gTempNumber == 2,
    [Note, [StrMerge, "Its a match: ", #gTempNumber]]
    ,
    [Note, [StrMerge, "Not a match: ", #gTempNumber]]
    ]


    The only workaround I can figure out is this, but surely this can't be the solution...

    [If, [StrMerge, "", #gTempNumber] == [StrMerge, "", 2],


    Brad | portfolio / blog: BRADfolio.com

  2. #2
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    It doesn't fail for me. Try putting parentheses around the comparison to see if that makes any difference. Also, try simply setting gTempNumber to 2 to see if you still get an error.

    Your workaround won't work as you can't use the comparison operator directly on strings in zscript. You can use StrFind instead:

    [VarDef,gTempNumberStr,""]
    [VarDef,gStr,"2"]
    [VarSet, gTempNumberStr, [IGet, Tool:Size:XYZ Size]]

    [If,(([StrFind,gStr,gTempNumberStr]==0)&&([StrFind,gTempNumberStr,gStr]==0)),
    [Note, [StrMerge, "Its a match: ", #gTempNumberStr]]
    ,
    [Note, [StrMerge, "Not a match: ", #gTempNumberStr]]
    ]


  3. #3
    Member Follow User Gallery
    Join Date
    Sep 2006
    Location
    Santa Monica, CA
    Posts
    88

    Default

    Thank you Marcus, I'm getting somewhere with your help, but now I have new concerns. Changes in my code don't evaluate as expected upon reloading the script. I have to restart ZBrush completely in order to see the code evaluate "correctly".

    You mentioned that I should try parentheses, and I remember doing that last night, and it still wouldn't work.

    As soon as I got to my computer this morning, I typed up the following: (the routine sets the geoSize array)

    [RoutineCall, Get_Geo_Size, #geoSize]
    [If, (#geoSize(0) == 2),

    This WORKED. However...

    I removed the parentheses and reloaded the script. It did not evaluate as expected. It failed like it did last night.

    [RoutineCall, Get_Geo_Size, #geoSize]
    [If, #geoSize(0) == 2,

    So I put the parentheses back, and reloaded the script again (Expecting it should work as it did previously). It did NOT evaluate as expected.

    I had to restart the application entirely to see my code evaluate as expected. This might be why I was stuck last night, no matter what I tried I couldn't get results that made any sense to me.

    Every heard of anything like that?

    The method I use to reloading / controlling is to use another reloading plugin with the following code:

    [ISubPalette, CONTROL_PLUGIN]


    [IButton, [StrMerge,#CONTROL_PLUGIN,":","Reload"], "",
    [If, [IExists, #CLOSE_PLUGIN], [IClose, #CLOSE_PLUGIN]]
    [FileNameSetNext, #CLOSE_FILE]
    [IPress, "ZScript:load"]
    ,,0.5]


    [IButton, [StrMerge,#CONTROL_PLUGIN,":","Close"], "",
    [If, [IExists, #CLOSE_PLUGIN], [IClose, #CLOSE_PLUGIN]]
    ,,0.5]
    Brad | portfolio / blog: BRADfolio.com

  4. #4
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    It sounds as though this is a variable declaration issue with the variable not being set correctly. But I can't tell from the code snippets you've posted. If you want to send me a message with the full code, I'll take a look.

  5. #5
    Member Follow User Gallery
    Join Date
    Sep 2006
    Location
    Santa Monica, CA
    Posts
    88

    Default

    Thank again Marcus. I may not be working on the script for another day or two. Next time I do, I'll declare a new variable and repeat the test to see what happens. I'll let you know the result. It was very reproducible for me this morning.

    If It doesn't work I'll probably take you up on the code sharing... but.. it may be hard to track down unless you have some tricks. I have a decent amount of modular, shareable code that gets zscript-inserted.
    Brad | portfolio / blog: BRADfolio.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •