Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Passing Parameters - unknown variable

    Scheduled Pinned Locked Moved
    General Discussion
    3
    5
    231
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • phoenixundefined
      phoenix
      last edited by

      Hello, I am trying to create a filament load macro, that gets called by the respective filament load button, or if called manually (which hotend was pressed is unknown) asks for which hotend to work with.

      I can't crack one final step - when running the macro (triggered, or called manually), I get an error: when triggered by the button it returns
      Error: in file macro line 4 column 23: meta command: unknown variable 'hotendselect'

      The sequence is first that the button triggers the trigger5.g file to pass on the value "2" :

      ; trigger5.g
      M98 P"0:/macros/filament-load" X2   ; Load Filament for T2
      

      then, the error is in Line 4 of the filament-load macro:

      ;Autoload filament macro. Press button then insert filament to load
      if exists(param.X)
        ; Parameter X was passed
        set var.hotendselect = param.X
        echo "Autoload for Extruder " ^ var.hotendselect
        else
        ; Parameter X was NOT passed, display screen for selecting one of the hotends
        M291 R"Unload Filament" P"Request for Extruder #" S4 K{0,1,2,3} J1
        set var.hotendselect = {input}
      endif
      
      T{var.hotendselect}                       ; Select Tool as passed on
      M300 S2000 P100   				              	; play beep sound
      M291 P"Insert filament in Tool!" S0 T3   	; display message
      M302 P1   	        				            	; enable cold extrusion
      G4 S5 						                      	; wait for 5 seconds to insert filament
      G1 E15 F500  				                   		; load filament inside the gears
      M109 S235 T0 					        	          ; set hotend temperature and wait
      G1 E100 F300 				          	        	; extrude 100mm, you may need to reduce speed for very soft TPU
      M104 S0 T0 					                    	; set hotend temperature to 0
      M302 P0 					                      	; disable cold extrusion
      M291 P"Filament autoload complete!" S0 T3 ; display message
      
      unset var.hotendselect                    ; Erase variable
      

      Apologies with what I assume is a noob question - I tried search, the GCode manual and chatGPT to no avail...

      jay_s_ukundefined fcwiltundefined 2 Replies Last reply Reply Quote 0
      • jay_s_ukundefined
        jay_s_uk @phoenix
        last edited by jay_s_uk

        @phoenix hotendselect will only be available inside the if. If you want it available in the rest of the macro declare it at the top before the if

        Endif also isn't valid

        And unset also isn't valid

        Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

        1 Reply Last reply Reply Quote 0
        • fcwiltundefined
          fcwilt @phoenix
          last edited by

          @phoenix

          Before you can user a variable in the form var.some_name you have to declare it using the form var some_name = 0, or whatever initial value you want it to have. Notice there is not period character between var and some_name in the declaration.

          Frederick

          Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

          1 Reply Last reply Reply Quote 0
          • phoenixundefined
            phoenix
            last edited by

            @fcwilt @jay_s_uk thanks for your help! I have now my first macros running 🙂

            fcwiltundefined 1 Reply Last reply Reply Quote 1
            • fcwiltundefined
              fcwilt @phoenix
              last edited by

              @phoenix

              That's why we are here!

              If we cannot help, we can mess things up in style. 🤠

              Frederick

              Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              Unless otherwise noted, all forum content is licensed under CC-BY-SA