Velo code works in Preview, but not Published

I have some simple code that is concatenating strings to produce some code for a 3D printer.

Recently an update appears to have happened to the back end code and now our public site no longer generates the printer’s code… instead, the browser’s dev tools is reporting an error.

When I go to the website editor, however, and test the code using the “preview” function, it works as expected. When I generate a test site or use the live published site, it fails with the error in this screenshot.

The web page that is failing is https://www.3dchameleon .com/gcodegenerator. There are several fields that need to be filled in; you can select Y, 100, 100, PrusaSlicer and hit the “Generate GCode” button to see it operate normally as a test.

However, in live mode, it fails as you see above.

Can anyone enlighten me as to what the issue might be… this appears to be a change on the back end causing it and I really don’t see anything in my code that could be causing it… especially, since it was working previously and we haven’t edited it recently.

Thanks for any help,

Bill

I might add, my code doesn’t use any external sources… it’s simply reading value from form fields and concatenating the strings.

Here is the actual code I use:

// API Reference: Introduction - Velo API Reference - Wix.com
// “Hello, World!” Example: Velo Learning Center
var toolChangeButtonPressCode = “G0 X3 Y3 F2000 ; press the button\nG4 P400 ; dwell for .3 seconds\nG0 X-3 Y-3 ; back off the button\nG4 S2; wait for it to happen” ;
var toolChangeButtonLoop = “” ;
var toolChangeButtonFlip = false ;
var toolChangeButtonLong = “P5500” ;
var toolChangeButtonShort = “P3500” ;
var activeExtruder = “T0” ;
const regex = /T0/ ig ;

$w . onReady ( function () {
// Write your JavaScript here

// To select an element by ID use: $w("#elementID") 

// Click "Preview" to run your code 

});

export function button1_click ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:

var  buttonAxis  =  "" ; 
var  buttonLocation  =  0 ; 
var  halfButton  =  0 ; 
var  loadLength  =  0 ; 
var  foobar  =  0 ; 
var  loadGCode  =  "" ; 
var  unloadGCode  =  "" ; 
var  buttonGCode  =  "" ; 
var  toolChangeGCode  =  "" ; 
var  toolChangeLoadGCode  =  "" ; 
var  toolChangeUnloadGCode  =  "" ; 
var  slicerGCode  =  "" ; 


buttonAxis  =  $w ( "#dropdown1" ). value ; 
buttonLocation  =  Number ( $w ( "#input1" ). value )- 3 ; 
halfButton  =  buttonLocation  /  2 ; 
loadLength  =  Number ( $w ( "#input2" ). value ); 
foobar  =  loadLength ; 

$w ( "#slicerStartOutput" ). hide (); 
$w ( "#slicerEndOutput" ). hide (); 

slicerGCode  =  "; Auto generated 3D Chameleon Tool Change GCode for "  +  $w ( "#dropdown2" ). value  +  "\n\n" ; 

if (( $w ( "#dropdown1" ). value )=== "X" ) 
{ 
    buttonGCode  =  "G0 X"  +  buttonLocation . toString () +  " Y"  +  halfButton . toString () +  " F2000 " ; 
} 
**else** 
{ 
    buttonGCode  =  "G0 X"  +  halfButton . toString () +  " Y"  +  buttonLocation . toString () +  " F2000 " ; 
} 

**switch**  ( $w ( "#dropdown2" ). value ) { 
    **case**  "PrusaSlicer" : 
        toolChangeGCode  =  slicerGCode  +  $w ( "#PrusaTemplate" ). text ;   
        break ; 
    **case**  "Simplify3D" : 
        toolChangeGCode  =  slicerGCode  +  $w ( "#Simplify3DTemplate" ). text ;  
        break ; 
    **case**  "Cura" : 
        toolChangeLoadGCode  =  slicerGCode  +  "; --- Extruder #"  +  $w ( "#dropdown3" ). value  +  " Start G-Code ---\n\n"  +  $w ( "#CuraStartProfile" ). text ; 
        toolChangeUnloadGCode  =  slicerGCode  +  "; --- Extruder #"  +  $w ( "#dropdown3" ). value  +  " End G-Code ---\n\n"  +  $w ( "#CuraEndProfile" ). text ; 
        break ; 
    **default** : 
        break ; 
} 

**for**  ( var  i  =  100 ;  i  <  loadLength ;  i = i + 100 ) { 
    unloadGCode  =  unloadGCode  +  "\nG92 E0\nG0 E-100 F2000" ; 
    loadGCode  =  loadGCode  +  "\nG92 E0\nG0 E100 F2000" ; 
    foobar  =  foobar  -  100 ; 
} 

unloadGCode  =  unloadGCode  +  "\n"  +  "G92 E0\nG0 E-"  +  foobar  +  " F2000\nG92 E0" ; 
loadGCode  =  loadGCode  +  "\n"  +  "G92 E0\nG0 E"  +  foobar  +  " F2000 ; <<<<<-----------  EDIT THIS DISTANCE TO FINE TUNE THE FILAMENT LOADING TO STOP BLOBBING OR UNDEREXTRUSION\nG92 E0" ; 

if (( $w ( "#dropdown2" ). value )=== "Cura" ) 
{ 
    toolChangeLoadGCode  =  toolChangeLoadGCode . replace ( "{buttonLocation}" ,  buttonGCode ); 
    toolChangeLoadGCode  =  toolChangeLoadGCode . replace ( "{loadGCode}" ,  loadGCode ); 
    toolChangeLoadGCode  =  toolChangeLoadGCode . replace ( regex ,  activeExtruder ); 
    toolChangeLoadGCode  =  toolChangeLoadGCode . replace ( "{buttonPressLoop}" ,  toolChangeButtonLoop ); 

    if ( toolChangeButtonFlip === **false** ) 
    { 
        toolChangeLoadGCode  =  toolChangeLoadGCode . replace ( "{buttonPressTime}" ,  toolChangeButtonLong ); 
        toolChangeUnloadGCode  =  toolChangeUnloadGCode . replace ( "{buttonPressTime}" ,  toolChangeButtonShort ); 
    } 
    **else** 
    { 
        toolChangeLoadGCode  =  toolChangeLoadGCode . replace ( "{buttonPressTime}" ,  toolChangeButtonShort ); 
        toolChangeUnloadGCode  =  toolChangeUnloadGCode . replace ( "{buttonPressTime}" ,  toolChangeButtonLong ); 
    } 

    toolChangeUnloadGCode  =  toolChangeUnloadGCode . replace ( "{buttonLocation}" ,  buttonGCode ); 
    toolChangeUnloadGCode  =  toolChangeUnloadGCode . replace ( "{unloadGCode}" ,  unloadGCode ); 
    toolChangeUnloadGCode  =  toolChangeUnloadGCode . replace ( regex ,  activeExtruder ); 

    $w ( "#slicerOutput" ). hide (); 
    $w ( "#slicerStartOutput" ). show (); 
    $w ( "#slicerEndOutput" ). show (); 

    $w ( "#slicerStartOutput" ). value  =  toolChangeLoadGCode ; 
    $w ( "#slicerEndOutput" ). value  =  toolChangeUnloadGCode ;    

} 
**else** 
{ 
    $w ( "#slicerOutput" ). show (); 
    $w ( "#slicerStartOutput" ). hide (); 
    $w ( "#slicerEndOutput" ). hide (); 

    toolChangeGCode  =  toolChangeGCode . replace ( "{buttonLocation}" ,  buttonGCode ); 
    toolChangeGCode  =  toolChangeGCode . replace ( "{unloadGCode}" ,  unloadGCode ); 
    toolChangeGCode  =  toolChangeGCode . replace ( "{loadGCode}" ,  loadGCode ); 
    $w ( "#slicerOutput" ). value  =  toolChangeGCode ; 
} 

}

export function dropdown2_change ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
if ( $w ( ‘#dropdown2’ ). value === “Cura” )
{
$w ( ‘#dropdown3’ ). enable ();
}
else
{
$w ( ‘#dropdown3’ ). disable ();
}
}

export function dropdown3_change ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
activeExtruder = “T” + ( Number (( $w ( ‘#dropdown3’ ). value ))- 1 ). toString ();
toolChangeButtonLoop = “” ;

var  loop  =  Number (( $w ( '#dropdown3' ). value ))- 1 ; 

if ( loop > 1 ) 
{ 
    toolChangeButtonFlip  =  **true** ; 
} 
**else** 
{ 
    toolChangeButtonFlip  =  **false** ; 
} 


**for**  ( var  i  =  0 ;  i  <  loop ;  i ++) 
{ 
    toolChangeButtonLoop  =  toolChangeButtonLoop  +  "\n"  +  toolChangeButtonPressCode  +  "\n" ; 
} 

}

Thanks for letting us know. I’ve shared the post with our Support team, and they will contact you about next steps.

Hi Bill!

The Customer Support team have just replied to you. Kindly find the email in your inbox

Kind regards,
Kateryna

I don’t know if Customer Support already fixed it
But i tried it and it seems to be working atm

Kind regards,
Kristof

@volkaertskristof Yes… It’s working now, thanks for your amazingly fast help!