Fixing VBScripts for Standalone VPX - surtarso/vpx-gui-tools GitHub Wiki

VBScript Issues and Workarounds

This page documents known issues with the VBScript interpreter in Visual Pinball Standalone, along with workarounds. Many issues have been fixed by the Wine team, and the Visual Pinball team has added several missing features (e.g., support for Eval, Execute, ExecuteGlobal, and GetRef). For more details, refer to the linked external resources.

[!NOTE] Many newer tables already know about these issues and work with no updates.


Table of Contents

  1. Syntax and Parsing Issues
  2. Declaration and Definition Issues
  3. Array and Evaluation Issues
  4. Loop and Type Conversion Issues
  5. Execution Issues
  6. Object and Shell Issues

Syntax and Parsing Issues

1. Parenthesis Order When Calling a Function

Issue:

' does not work
addscore (starstate+1)*1000    

Workarounds:

  • Option 1:
    addscore 1000*(starstate+1)
    
  • Option 2:
    addscore ((starstate+1)*1000)
    

[!Tip] This issue is hard to spot as the parser does not provide an exact error line. Bisecting the script may help locate the problem.
See: Wine Bug #54177(https://bugs.winehq.org/show_bug.cgi?id=54177)


2. Using Not in an If Statement Needs Parentheses

Issue:

' does not work
If isGIOn <> Not IsOff Then

Workaround:

If isGIOn <> (Not IsOff) Then

See: Wine Bug #55093(https://bugs.winehq.org/show_bug.cgi?id=55093)


3. Else..End If on the Same Line Without a Colon

Issue:

' does not work
else keygrad1 = 0 end if

Workaround:

else 
   keygrad1 = 0 
end if

4. Colon on a New Line After Then Fails to Compile

Issue:

' does not work
If Keycode = StartGameKey Then
  :pupevent 800
End If

Workaround:

If Keycode = StartGameKey Then
  pupevent 800
End If

See: Wine Bug #55037(https://bugs.winehq.org/show_bug.cgi?id=55037)


Declaration and Definition Issues

5. Constants Must Be Defined Before They Are Used

Issue:

' does not work
Dim x
x = data
Const data = 1

Workaround:

Const data = 1
Dim x
x = data

[!IMPORTANT] Always define constants before using them to prevent runtime errors.


Array and Evaluation Issues

6. Setting Values in a 2D Array

Issue:

' does not work
DTArray(i)(4) = DTCheckBrick(Activeball,DTArray(i)(2))        

Workaround:

DTArray(i).animate = DTCheckBrick(Activeball,DTArray(i).prim) ' move to class approach

[!Note] This is one of the most common issues. It can be automatically patched by vpxtool.
See: DTArray Drop Targets(https://github.com/vpinball/vpinball/tree/standalone/standalone#dtarray-drop-targets), STArray Standup Targets(https://github.com/vpinball/vpinball/tree/standalone/standalone#starray-standup-targets), and Wine Bug #53877(https://bugs.winehq.org/show_bug.cgi?id=53877)


7. Evals Fail When Setting a 2D Array

Issue:

' does not work
dy = -1*(EVAL("roachxy" & xx)(1)(roachstep) - EVAL("roachxy" & xx)(1)(roachstep-1)) 'delta Y

Workaround:

dim roachxy : roachxy = EVAL("roachxy" & xx)
dy = -1*(roachxy(1)(roachstep) - roachxy(1)(roachstep-1)) 'delta Y

Loop and Type Conversion Issues

8. Coercion Issue in a For Loop When Right Bound Is a String

Issue:

' This code loops 16 times on Windows but on Linux it leads to a very large numerical value.
' This results in the loop iterating an extremely high number of times.
Dim i, num
num = "16"
For i = 0 To num
    WScript.Echo i
Next

Workaround:

For i = 0 To CInt(num)

See: Wine Bug #55052(https://bugs.winehq.org/show_bug.cgi?id=55052)


Execution Issues

9. Execute Fails When Object Does Not Exist

Issue:

' does not work
For i = 0 To 127: Execute "Set Lights(" & i & ") = L" & i: Next   

Workaround:

For i = 0 To 127
    If IsObject(Eval("L" & i)) Then
        Execute "Set Lights(" & i & ") = L" & i
    End If
Next

10. Trailing Else Without End If

Issue:

' does not work (notice no End If)
If FlasherOnG = False then FlasherTimer3.Enabled = 1: Else 
FlasherTimer4.Enabled = 0

Workaround:

If FlasherOnG = False then FlasherTimer3.Enabled = 1
FlasherTimer4.Enabled = 0

See: Wine Bug #55006(https://bugs.winehq.org/show_bug.cgi?id=55006)


Object and Shell Issues

11. WScript.Shell Does Not Work

Issue:

' does not work
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
GetNVramPath = WshShell.RegRead("HKEY_CURRENT_USER\Software\Freeware\Visual PinMame\globals\nvram_directory")

[!WARNING] There is no workaround because the Standalone version will not support WScript.Shell.

[!TIP] Sometimes you can just comment out the line.


12. Table Crashes Immediately After Ball Hits Flipper

Issue:

' CorTracker
Public Sub Update()    ' tracks in-ball-velocity
   Dim str, b, AllBalls, highestID : AllBalls = gBOT

Workaround:

Public Sub Update()    ' tracks in-ball-velocity
   Dim str, b, AllBalls, highestID : AllBalls = getballs

[!NOTE] VBScript uses reference counters for objects. In this case, using gBOT may reduce a ball's reference count to zero, leading to its destruction and causing subsequent code to crash when accessing a destroyed object.


Conclusion

Many of these issues stem from differences in how VBScript is interpreted in the Wine environment compared to native Windows environments. Where possible, workarounds are provided. For further automation, consider using tools like vpxtool.

[!TIP] If you encounter any new issues, check the Wine project's bug tracker for similar reports.


This document is intended to help developers quickly identify and resolve common VBScript issues in Visual Pinball Standalone.