Author Topic: Scripting - Variable Help  (Read 675 times)

0 Members and 1 Guest are viewing this topic.

Offline wellmr7Topic starter

  • Active Member
  • **
  • Posts: 2
  • Country: us
  • Gender: Male
Scripting - Variable Help
« on: Nov 11, 2024, 15:20:12 PM »
Hi all,

I'm very new to scripting, so I may be missing something obvious here - but I can't get functions to work where I've used "DIM" to assign a variable.

I have a test job where I am messing around with elbow throats - just trying to get comfortable with calling data and making changes, etc.

The elbows in my job all have a top extension of 6" and a bottom of 8"

The script as listed should change the bottom extension to 2". Running debug, everything looks like it should work, but upon running the script with no errors present, the values are not updated. I've inserted item.update() in various places with no success.

If I run the same script without defining variables and use item.dim#.value, everything works fine. It seems like there's a breakdown somewhere after "end function", but I can't figure it out. I've created many other practice scripts where assigning variables are not working for me, but long form always does.

I am hoping some of you would please point out where I am going astray!

I know that I don't necessarily need to make a function to accomplish this. I have written it long form and have accomplished the changes in just a few lines. I'm just playing around with different things, trying to get comfortable with writing scripts. I have relatively no experience with scripting or coding.

Code: [Select]
function ThroatSize()

dim top=item.dim[4].value
dim bottom=item.dim[5].value

debug top + " / " + bottom   ---------> THIS REPORTS THE CORRECT INITIAL VALUE OF "6/8"

if top <=6 then
   bottom  = 2

endif

debug top + " / " + bottom   ----------> THIS REPORTS THE CORRECT CHANGED VALUE OF "6/2"

end function

select item.cid
       case 3

ThroatSize()
end select    --------> DIMENSION 5, BOTTOM EXTENSION REMAINS UNCHANGED AT 8"

Offline AN-detail

  • Active Member
  • **
  • Posts: 18
  • Country: us
  • Gender: Male
Re: Scripting - Variable Help
« Reply #1 on: Nov 11, 2024, 17:46:16 PM »
You can read properties as variables, but you can't write properties that way.

if top <=6 then
   bottom  = 2
   item.dim[5].value = 2

Also, the line "bottom = 2" is setting the variable bottom to 2, not item.dim[5].value to 2. That's why 'debug top + " / " + bottom' still returns correct

Offline wellmr7Topic starter

  • Active Member
  • **
  • Posts: 2
  • Country: us
  • Gender: Male
Re: Scripting - Variable Help
« Reply #2 on: Nov 11, 2024, 17:53:41 PM »
Thanks! That is extremely helpful and explains a lot!