I have a tool change that is close, but doesn't recognize a global variable how I want it to. If anybody can take a look I'd appreciate it.

Basically, my CAM program calls SetTool(1) to fetch Tool #1.

It checks what tool it currently has, a global INT CurrentTool.

If CurrentTool is different than called, here it returns Tool X and fetches Tool 1.

Lastly, CurrentTool =fetched tool.

the problem is that the INT CurrentTool is not being updated via the subprogram. I set it to 2, ran a test program that called SetTool(1), but it skipped the Tool 2 return (the CurrentTool switch) and went straight to fetching Tool 1.

Apologies for all the Folds, I don't know how to collapse them.

```
&ACCESS RVO1
&REL 35
&PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe
&PARAM EDITMASK = *
DEF SetTool(GetTool:IN)
DECL INT GetTool
;FOLD INI
;FOLD BASISTECH INI
GLOBAL INTERRUPT DECL 3 WHEN $STOPMESS==TRUE DO IR_STOPM ( )
INTERRUPT ON 3
BAS (#INITMOV,0 )
;ENDFOLD (BASISTECH INI)
;FOLD USER INI
;Make your modifications here
;ENDFOLD (USER INI)
;ENDFOLD (INI)
;FOLD PTP prerest Vel=30 % PDAT1 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:prerest, 3:, 5:30, 7:PDAT1
$BWDSTART=FALSE
PDAT_ACT=PPDAT1
FDAT_ACT=Fprerest
BAS(#PTP_PARAMS,30)
PTP Xprerest
;ENDFOLD
IF CurrentTool<>GetTool THEN
;FOLD PTP pretool Vel=30 % PDAT2 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:pretool, 3:, 5:30, 7:PDAT2
$BWDSTART=FALSE
PDAT_ACT=PPDAT2
FDAT_ACT=Fpretool
BAS(#PTP_PARAMS,30)
PTP Xpretool
;ENDFOLD
SWITCH CurrentTool ;drop current tool
; Case 0 ; do nothing
Case 1 ;return tool 1
;FOLD LIN AboveLoad3 Vel=0.2 m/s CPDAT9 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:AboveLoad3, 3:, 5:0.2, 7:CPDAT9
$BWDSTART=FALSE
LDAT_ACT=LCPDAT9
FDAT_ACT=FAboveLoad3
BAS(#CP_PARAMS,0.2)
LIN XAboveLoad3
;ENDFOLD
;FOLD LIN loadpoint3 Vel=0.2 m/s CPDAT10 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:loadpoint3, 3:, 5:0.2, 7:CPDAT10
$BWDSTART=FALSE
LDAT_ACT=LCPDAT10
FDAT_ACT=Floadpoint3
BAS(#CP_PARAMS,0.2)
LIN Xloadpoint3
;ENDFOLD
;FOLD LIN lockpoint3 Vel=0.2 m/s CPDAT11 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:lockpoint3, 3:, 5:0.2, 7:CPDAT11
$BWDSTART=FALSE
LDAT_ACT=LCPDAT11
FDAT_ACT=Flockpoint3
BAS(#CP_PARAMS,0.2)
LIN Xlockpoint3
;ENDFOLD
soClampRelease = true
wait sec 0.5
;FOLD LIN abovelock1 Vel=0.2 m/s CPDAT5 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:abovelock1, 3:, 5:0.2, 7:CPDAT5
$BWDSTART=FALSE
LDAT_ACT=LCPDAT5
FDAT_ACT=Fabovelock1
BAS(#CP_PARAMS,0.2)
LIN Xabovelock1
;ENDFOLD
Case 2 ;return tool 2
;FOLD LIN AboveLoad2 Vel=0.2 m/s CPDAT12 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:AboveLoad2, 3:, 5:0.2, 7:CPDAT12
$BWDSTART=FALSE
LDAT_ACT=LCPDAT12
FDAT_ACT=FAboveLoad2
BAS(#CP_PARAMS,0.2)
LIN XAboveLoad2
;ENDFOLD
;FOLD LIN loadpoint2 Vel=0.2 m/s CPDAT13 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:loadpoint2, 3:, 5:0.2, 7:CPDAT13
$BWDSTART=FALSE
LDAT_ACT=LCPDAT13
FDAT_ACT=Floadpoint2
BAS(#CP_PARAMS,0.2)
LIN Xloadpoint2
;ENDFOLD
;FOLD LIN lockpoint2 Vel=0.2 m/s CPDAT14 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:lockpoint2, 3:, 5:0.2, 7:CPDAT14
$BWDSTART=FALSE
LDAT_ACT=LCPDAT14
FDAT_ACT=Flockpoint2
BAS(#CP_PARAMS,0.2)
LIN Xlockpoint2
;ENDFOLD
soClampRelease = true
wait sec 0.5
;FOLD LIN abovelock2 Vel=0.2 m/s CPDAT15 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:abovelock2, 3:, 5:0.2, 7:CPDAT15
$BWDSTART=FALSE
LDAT_ACT=LCPDAT15
FDAT_ACT=Fabovelock2
BAS(#CP_PARAMS,0.2)
LIN Xabovelock2
;ENDFOLD
Case 3 ;return tool 3
;FOLD LIN AboveLoad3 Vel=0.2 m/s CPDAT16 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:AboveLoad3, 3:, 5:0.2, 7:CPDAT16
$BWDSTART=FALSE
LDAT_ACT=LCPDAT16
FDAT_ACT=FAboveLoad3
BAS(#CP_PARAMS,0.2)
LIN XAboveLoad3
;ENDFOLD
;FOLD LIN loadpoint3 Vel=0.2 m/s CPDAT17 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:loadpoint3, 3:, 5:0.2, 7:CPDAT17
$BWDSTART=FALSE
LDAT_ACT=LCPDAT17
FDAT_ACT=Floadpoint3
BAS(#CP_PARAMS,0.2)
LIN Xloadpoint3
;ENDFOLD
;FOLD LIN lockpoint3 Vel=0.2 m/s CPDAT18 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:lockpoint3, 3:, 5:0.2, 7:CPDAT18
$BWDSTART=FALSE
LDAT_ACT=LCPDAT18
FDAT_ACT=Flockpoint3
BAS(#CP_PARAMS,0.2)
LIN Xlockpoint3
;ENDFOLD
soClampRelease = true
wait sec 0.5
;FOLD LIN abovelock3 Vel=0.2 m/s CPDAT19 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:abovelock3, 3:, 5:0.2, 7:CPDAT19
$BWDSTART=FALSE
LDAT_ACT=LCPDAT19
FDAT_ACT=Fabovelock3
BAS(#CP_PARAMS,0.2)
LIN Xabovelock3
;ENDFOLD
ENDSWITCH
ENDIF
;FOLD PTP pretool Vel=40 % PDAT2 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:pretool, 3:, 5:40, 7:PDAT2
$BWDSTART=FALSE
PDAT_ACT=PPDAT2
FDAT_ACT=Fpretool
BAS(#PTP_PARAMS,40)
PTP Xpretool
;ENDFOLD
SWITCH GetTool ;get called tool
CASE 1
;FOLD LIN abovelock1 Vel=0.2 m/s CPDAT1 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:abovelock1, 3:, 5:0.2, 7:CPDAT1
$BWDSTART=FALSE
LDAT_ACT=LCPDAT1
FDAT_ACT=Fabovelock1
BAS(#CP_PARAMS,0.2)
LIN Xabovelock1
;ENDFOLD
soClampRelease = TRUE
wait sec 0.5
;FOLD LIN lockpoint1 Vel=0.2 m/s CPDAT2 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:lockpoint1, 3:, 5:0.2, 7:CPDAT2
$BWDSTART=FALSE
LDAT_ACT=LCPDAT2
FDAT_ACT=Flockpoint1
BAS(#CP_PARAMS,0.2)
LIN Xlockpoint1
;ENDFOLD
soClampRelease=FALSE
wait sec 1
;FOLD LIN loadpoint1 Vel=0.2 m/s CPDAT3 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:loadpoint1, 3:, 5:0.2, 7:CPDAT3
$BWDSTART=FALSE
LDAT_ACT=LCPDAT3
FDAT_ACT=Floadpoint1
BAS(#CP_PARAMS,0.2)
LIN Xloadpoint1
;ENDFOLD
;FOLD LIN AboveLoad1 Vel=0.2 m/s CPDAT4 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:AboveLoad1, 3:, 5:0.2, 7:CPDAT4
$BWDSTART=FALSE
LDAT_ACT=LCPDAT4
FDAT_ACT=FAboveLoad1
BAS(#CP_PARAMS,0.2)
LIN XAboveLoad1
;ENDFOLD
;currenttool=1
CASE 2
;FOLD LIN abovelock2 Vel=0.2 m/s CPDAT20 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:abovelock2, 3:, 5:0.2, 7:CPDAT20
$BWDSTART=FALSE
LDAT_ACT=LCPDAT20
FDAT_ACT=Fabovelock2
BAS(#CP_PARAMS,0.2)
LIN Xabovelock2
;ENDFOLD
soClampRelease = TRUE
wait sec 0.5
;FOLD LIN lockpoint2 Vel=0.2 m/s CPDAT21 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:lockpoint2, 3:, 5:0.2, 7:CPDAT21
$BWDSTART=FALSE
LDAT_ACT=LCPDAT21
FDAT_ACT=Flockpoint2
BAS(#CP_PARAMS,0.2)
LIN Xlockpoint2
;ENDFOLD
soClampRelease=FALSE
wait sec 1
;FOLD LIN loadpoint2 Vel=0.2 m/s CPDAT22 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:loadpoint2, 3:, 5:0.2, 7:CPDAT22
$BWDSTART=FALSE
LDAT_ACT=LCPDAT22
FDAT_ACT=Floadpoint2
BAS(#CP_PARAMS,0.2)
LIN Xloadpoint2
;ENDFOLD
;FOLD LIN AboveLoad2 Vel=0.2 m/s CPDAT23 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:AboveLoad2, 3:, 5:0.2, 7:CPDAT23
$BWDSTART=FALSE
LDAT_ACT=LCPDAT23
FDAT_ACT=FAboveLoad2
BAS(#CP_PARAMS,0.2)
LIN XAboveLoad2
;ENDFOLD
;currenttool=2
CASE 3
;FOLD LIN abovelock3 Vel=0.2 m/s CPDAT24 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:abovelock3, 3:, 5:0.2, 7:CPDAT24
$BWDSTART=FALSE
LDAT_ACT=LCPDAT24
FDAT_ACT=Fabovelock3
BAS(#CP_PARAMS,0.2)
LIN Xabovelock3
;ENDFOLD
soClampRelease = TRUE
wait sec 0.5
;FOLD LIN lockpoint3 Vel=0.2 m/s CPDAT25 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:lockpoint3, 3:, 5:0.2, 7:CPDAT25
$BWDSTART=FALSE
LDAT_ACT=LCPDAT25
FDAT_ACT=Flockpoint3
BAS(#CP_PARAMS,0.2)
LIN Xlockpoint3
;ENDFOLD
soClampRelease=FALSE
wait sec 1
;FOLD LIN loadpoint3 Vel=0.2 m/s CPDAT26 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:loadpoint3, 3:, 5:0.2, 7:CPDAT26
$BWDSTART=FALSE
LDAT_ACT=LCPDAT26
FDAT_ACT=Floadpoint3
BAS(#CP_PARAMS,0.2)
LIN Xloadpoint3
;ENDFOLD
;FOLD LIN AboveLoad3 Vel=0.2 m/s CPDAT27 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VLIN,%P 1:LIN, 2:AboveLoad3, 3:, 5:0.2, 7:CPDAT27
$BWDSTART=FALSE
LDAT_ACT=LCPDAT27
FDAT_ACT=FAboveLoad3
BAS(#CP_PARAMS,0.2)
LIN XAboveLoad3
;ENDFOLD
;currenttool=3
ENDSWITCH
;FOLD PTP pretool Vel=40 % PDAT4 Tool[0] Base[0];%{PE}%R 5.6.13,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:pretool, 3:, 5:40, 7:PDAT4
$BWDSTART=FALSE
PDAT_ACT=PPDAT4
FDAT_ACT=Fpretool
BAS(#PTP_PARAMS,40)
PTP Xpretool
;ENDFOLD
currenttool=gettool
END
```

Display More