If you haven't noticed, many scripted models will operate in SU 2013 and below. This is due to SU2013 and SU2014 using different Ruby versions. SU2013 and lower use Ruby 1.8.x, while SU2014 uses Ruby 2.0.0. There were Ruby implementation changes since 1.8.x. Make sure your script is updated to be compatible with the following changes:

Ruby Changes[]

Prohibited use of spaces between method name and the parentheses[]

  • Bad (1,2,3)
  • Good,2,3)

Prohibited use of colons (:) in case-when statement. Use semicolons (;) or new line.[]

  • Bad
 case count
 when 1: puts 'hello'
 when 2: puts 'goodbye'
  • Good
 case count
 when 1; puts 'hello'
 when 2; puts 'goodbye'
  • Also good
 case count
 when 1
   puts 'hello'
 when 2
   puts 'goodbye'

Replaced Hash.#index with Hash.#key[]

 my_hash = { 1 => 'hello', 2 => 'goodbye' }
  • Bad (.index works in SU2013 and below only)
 count = my_hash.index('hello')
  • Bad (.key works in SU2014 only)
 count = my_hash.key('hello')
  • Good (works in both versions)
 if RUBY_VERSION =~ /1.8/
   count = my_hash.index('hello')
   count = my_hash.key('hello')
  • Also good (one liner):
 count = RUBY_VERSION =~ /1.8/ ? my_hash.index('hello') : my_hash.key('hello')

Making LazyScript Compatible[]

For some advanced scripted models that use LazyScript making their code compatible for SU2014 is not enough because (1) LazyScript itself needs to be updated with Ruby changes, and (2) LazyScript needs to ensure that it is using Fiddle for Ruby 2.0 and DL for Ruby 1.8. In Ruby 2.0.0 Ruby DL was deprecated and replaced with Fiddle. Change body pointer creators to use DL or Fiddle, depending on Ruby version:

  • From this
 body_ptr =
  • To this
 body_ptr = RUBY_VERSION =~ /1.8/ ? :

Rule to Keep in Mind[]

In SP3.2 many advanced scripted models relied on modifying SP content to achieve something that wasn't achievable via the standard SP API. For instance, many would modify onMouseMove(x, y, view, flags) function to get cursor position, and some would modify the draw(view) for a better drawing features.

Modifying SP content is a bad practice because it may break compatibility with future SP versions. SP 3.5 has functions and events that should give a developer what he/she wants. For instance, to get cursor position use, $sketchyPhysicsToolInstance.cursorPos. If you want to improve the draw tool, simply use the onDraw { |view, bb| } event rather than modifying the draw(view) function. If you want something to be done in the nextFrame, don't modify the nextFrame function, use onPreFrame, onTick, or onPostFrame events. Same goes to start and reset physics; use onStart, and onEnd events. Modifying SP content in SP3.3+ is no longer required because there are events and functions that should give you what you want.

That's about it ;)