Variable Mismatch

Home Forums Problems and solutions in GDL Others Variable Mismatch

This topic contains 19 replies, has 3 voices, and was last updated by  Lingwisyer GC 1 year ago.

  • Author
    Posts
  • #4787

    Lingwisyer GC
    Participant

    Hi all,

    I appear to have a variable mismatch in the following section of code. Code has been clipped to executed sections. Text outputting my check variable cc returns 0.305 which is correct, therefore at this stage of the code, SquareV2 = 0.305. Yet if I set Pitch_off to 50, SquareV returns -35, which if we work backwards gives SquareV2 = 0.010 rather than the expected 0.305.

    If SquareV > SquareV2 - Pitch_off * tan(35) then SquareV = SquareV2 - Pitch_off * tan(35)
    
    If Pitch_off > (SquareV2 - SquareV) / tan(35) then Pitch_off = (SquareV2 - SquareV) / tan(35)
    
    cc = SquareV2

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4788

    Péter Baksa
    Participant

    Hi, is this in a parameter script? Are these variables or parameters?

    Péter Baksa
    Library Platform, Software Engineer
    GRAPHISOFT SE

  • #4789

    Lingwisyer GC
    Participant

    This is from my Master Script. Used to set minimum and maximum limits depending on the values set for other parameters.

    cc is a variable, the others are parameters.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4790

    Péter Baksa
    Participant

    If you have VALUES or PARAMETERS based on these in the parameter script, it is possible that the param script is run more than once, and the code you wrote will be executed more than once with different parameter values. Your condition B is based on A, but in the next run A is based on the last run of B.

    You might need to use GLOB_MODPAR_NAME in the parameter script, based on which parameter the user changed, only one of the limiting conditions has to be applied.

    Péter Baksa
    Library Platform, Software Engineer
    GRAPHISOFT SE

  • #4791

    Lingwisyer GC
    Participant

    Setting SquareV and Pitch_off to only update when they are modified has no affect. They only affect each other.
    Disabling the update of these two allows the script to work, but results in it being possible for values to show that are not the ones being used, being outside the min / max.
    If I swap parameter “SquareV2” with 0.305 the Master Script works as it is suppose to for that value.

    I think you might be right about the Parameter Script being run multiple times, or at least run before the 2D and 3D Scripts. Is there a way to force the Parameter Script to only run once after executing the 2D and 3D scripts?

    “SquareV2” does not resolve in the Parameter Script due to being calculated using a requested value, yet if I say “PARAMETERS SquareV2 = 0.305” the incorrect values are still used. This seems to imply the the Master Script is run, then the Parameter Script is looped before the 2D and 3D scripts OR it is just getting confused by the input value from the Parameter Script, and the value calculated in the Master Script and returning 0.

    Returning 0 is more desirable then returning incorrect values.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4792

    Barry Kelly
    Participant

    I am a little confused by your script.
    ‘SquareV2’ should never change as nowhere in your formula are you setting the value for it.

    To check for the ‘firstrun’ of the parameter script, you can try using this to catch it…

    First Occasion in Progress
    n = APPLICATION_QUERY (“parameter_script”, “firstoccasion_in_progress”, isFirstRun)
    This command returns whether the current run is the first run or a consequence of a previous execution of the parameter script which changed
    some parameters. This command has no additional parameters.
    The distinction may be important when a part of the parameter script executes a triggered event – e.g. it handles the pushing of a function button.
    isFirstRun: The returned value shows whether the current run is the first run

    Barry.

    Versions 6.5 to 22
    Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
    Dell Precision M6800 - i7 4700MQ @ 2.40GHz, 16GB RAM, AMD FirePro M6100 (2GB), Windows 7 64bit

  • #4793

    Lingwisyer GC
    Participant

    I am a little confused by your script.

    That is just a clipped section of my script.

    ProHeight = abs(_yMax - _yMin)
    SquareV2 = ProHeight / ( cos(phi) )

    Due to requests not being resolved in the Parameter Script, this section will return an incorrect value when it is run for this script.

    n = APPLICATION_QUERY (“parameter_script”, “firstoccasion_in_progress”, isFirstRun)

    So I would include that query in my Master Script and get it to not execute if the Parameter Script has been run more than once?

    If isFirstRun > 1 then goto MasterEnd

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4794

    Lingwisyer GC
    Participant

    Phi in the original script was substituted with 35.

    Well… that was unexpected. So I added the “isFirstRun” query to the start of my Master Script followed by a “GOTO MasterEnd” and it appears to all be working. My limits are even showing in the Parameter Script, even though SquareV2 is not being resolved.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

    • #4795

      Lingwisyer GC
      Participant

      Whelp. Forum will not allow me to edit that post. It did not actually fix anything. Had forgotten to change some substituted values back to the parameter Squarev2.

      AC18-23 AUS 4006
      Self-taught, bend it till it breaks.
      Win7 | E5620 x 2 | 24GB | K2200

  • #4796

    Lingwisyer GC
    Participant

    The Parameter Script needs only to run after the other scripts have run or when it is first initiallised.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4797

    Barry Kelly
    Participant

    I would say …

    IF isFirstRun THEN
    	execute code....
    ENDIF

    At least this is what has been mentioned in other posts about it.
    I think it may be a little confusing and ‘isfirstrun’ only gets a value when it is the first run.
    I am not sure if it gets a higher value on multiple parameter script runs.

    I still don’t understand your code.

    ProHeight = abs(_yMax - _yMin)
    SquareV2 = ProHeight / ( cos(phi) )

    SquareV2 still has nothing to do with the first bit of code you posted.

    Barry.

    Versions 6.5 to 22
    Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
    Dell Precision M6800 - i7 4700MQ @ 2.40GHz, 16GB RAM, AMD FirePro M6100 (2GB), Windows 7 64bit

  • #4798

    Lingwisyer GC
    Participant

    This object has the option to use complex profiles. The issue only occurs when a complex profile is used. The original two equations include SquareV2 and if skipped, the 2D and 3D resolve correctly.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4799

    Péter Baksa
    Participant

    Don’t think about the master script on its own, in fact it is prepended to the actual script that is run. So it doesn’t help with requests that can’t be used in a parameter script.
    You can’t control the execution order of the scripts, generally parameter script is run before the 2D/3D.
    Something like this:

    master script -> param script: sets parameters
    all variables cleared
    master script again with the new parameters -> param script: sets other parameters
    all variables cleared
    master script again with the new parameters -> 2D script
    all variables cleared
    master script again with the same new parameters -> 3D script

    Péter Baksa
    Library Platform, Software Engineer
    GRAPHISOFT SE

  • #4813

    Lingwisyer GC
    Participant

    So, I included the following in my Interface Script;

    	n2 = REQUEST ("Profile_default_boundingbox",  myProfileIdx, _xMin, _yMin, _xMax, _yMax)
    
    	ProWidth = abs(_xMax - _xMin)
    	ProHeight = abs(_yMax - _yMin)
    	SquareV2 = ProHeight / ( cos(phi) )

    but they appear to have no effect. ProWidth returns 50, ProHeight returns 100 and SquareV2 returns 0 no matter the size of the profile set…

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4814

    Péter Baksa
    Participant

    Is that a parametric profile, or are you selecting different profile for myProfileIdx?
    Parametric profiles don’t work with GDL, they always return their default geometry.

    Péter Baksa
    Library Platform, Software Engineer
    GRAPHISOFT SE

  • #4815

    Lingwisyer GC
    Participant

    Should probably reword “profile set” to “value of myProfileIdx”.

    Some of them probably are, but it does not even return the default values.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4816

    Péter Baksa
    Participant

    Then this should work. How do you check the return values?

    Péter Baksa
    Library Platform, Software Engineer
    GRAPHISOFT SE

  • #4820

    Lingwisyer GC
    Participant

    In the 2D Script, I have a TEXT2 that outputs the values.
    In the Interface Script I have an UI_INFIELD that outputs the same values.

    Neither of the scripts contain anything that modifies any of the parameters so they should both be reading the same values from the Master Script, yet only the 2D Script is returning the correct values.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

  • #4821

    Péter Baksa
    Participant

    The 2d script doesn’t know about the variables in the UI script. You have to write the same request in the 2D script too, or move it to the master script (just don’t use the variables in the parameter script, as the request will be unsuccessful from parameter script).
    UI_INFIELD can’t show variables. Is ProWidth and ProHeight a parameter? No matter what you assign to it in the scripts, UI_INFIELD will show the stored parameter values. You would need a PARAMETERS command to change them, but you can’t do it, as this request doesn’t work in parameter script.
    You can show variables and current value of parameters with UI_OUTFIELD.

    Péter Baksa
    Library Platform, Software Engineer
    GRAPHISOFT SE

  • #4824

    Lingwisyer GC
    Participant

    The 2d script doesn’t know about the variables in the UI script.

    Everything else is in the Master Script. It is just a ‘text2 a’ and a ‘ui_outfield a’ found in their respective scripts.

    You can show variables and current value of parameters with UI_OUTFIELD.

    That works. I never thought of using an infield for displaying a parameter.

    Ling.

    AC18-23 AUS 4006
    Self-taught, bend it till it breaks.
    Win7 | E5620 x 2 | 24GB | K2200

You must be logged in to reply to this topic.