Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Training AI to understand FSR

For general discussion related FlowStone

Training AI to understand FSR

Postby billv » Fri May 01, 2026 3:48 am

You may have noticed that your AI is hopeless when it comes to FS Ruby.
The solution is to write your own API, so the AI can understand.
Its not that hard, only takes a few hours. :)
It practically removes all syntax errors and false method calls,for eg.
Here's the one I built (bear in mind, it is built for me, and not you)
I highly recommend you build your own so it fits "Your" Ruby personality.
Then your AI will spit nice FSR code that is to your liking.
Code: Select all
# =========================================================
# FSR BRAIN API— BY BILL VALIONTIS
# =========================================================
# Flostone Ruby is a HOSTILE enviroment. Do not deviate from this API.
# =========================================================
# ------------------API RULES AND REGULATIONS
# =========================================================
# Code to written in same order
# Hard boot/init/nilerrors/events/methods/tick/mouse+keys/draw
# All code to seperated by comments and titles
# Always print out full code on rubyedit, unless I ask for a snippet
# Every time you print full code, give it a title and number like Breakout_01
# Avoid using local variable and use Instance variables instead
# Avoid hash usage
# Avoid for-loops
# Prefer 4.times do |i|
# All colors external
# Restart logic must work from beginning of build
# Troubleshoot correct subsystem only
# Never deviate from API

# =========================================================
# ------------------INPUTS AND OUTPUTS
# =========================================================
# input 0, View (View is refreshed by external ticker)
# input 1, Trig (Reset)
# input 2, Boolean (On/Off)
# input 3, Color @col1
# input 4, Color @col2
# input 5, Color @col3
# input 6, Color @col4
# input 7, Color @col5
# input 8, Color @col6
#--------------------------------------------------
# There is NO "Puts" or "Print" in this language.
# output 0, "Example string"
# output 1, "Example string"
# =========================================================
# ------------------MIDI
# =========================================================
# Midi must be written in  codeblock def event i,v,t
        def event i,v,t
            on  = Midi.new 144, 1, 60, 100
            off = Midi.new 128, 1, 60, 100
            output 0, on
            output 0, off, t + 0.25
        end
# =========================================================
# ------------------TICK
# =========================================================
        TICK_RATE = 0.25
        def init
            @angle = 0.0
            scheduleMethod 'tick', time + TICK_RATE
        end

        def tick
            redraw
            scheduleMethod 'tick', time + TICK_RATE
        end
# =========================================================
# ------------------MOUSE AND KEYBOARD
# =========================================================
        def isInMousePoint x,y  #-- Mandatory
        end

        def mouseLDown x,y
            captureMouse
        end

        def mouseMoveCaptured x,y
            output [x,y]
        end

        def mouseLUp x,y
            releaseMouse
        end
# ----------------------KEYBOARD--------------------------
        if isKeyPressed(32)
           output 0, "Spacebar"
        end 
# =========================================================
# ------------------HARD BOOT
# =========================================================
        def hard_boot
            @boot = true
        end

        def draw(v)
            hard_boot unless @boot       
        end
# =========================================================
# ------------------ARRAYS
# =========================================================
#              1. Adding & Removing Elements
# These are essential for managing data streams coming from Flowstone's inputs.
# push(obj) or <<: Adds an item to the end.
# pop: Removes and returns the last item.
# unshift(obj): Adds an item to the beginning.
# shift: Removes and returns the first item.
# insert(index, obj): Inserts an item at a specific position.
# delete(obj): Removes all items equal to obj.
# delete_at(index): Removes the item at a specific index.
#              2. Accessing & Information
# length (or size): Returns the number of elements.
# at(index) or [index]: Gets the element at that position.
# first / last: Returns the first or last element.
# include?(obj): Returns true if the object exists in the array.
# index(obj): Returns the index of the first object matching obj.
# empty?: Returns true if the array has no elements.
#              3. Transformation & Iteration
# each { |i| ... }: Standard loop through every item.
# map { |i| ... } (or collect): Creates a new array by applying the block to every element.
# select { |i| ... }: Returns a new array containing only items where the block is true.
# reject { |i| ... }: The opposite of select.
# compact: Removes all nil values.
# flatten: Flattens a nested array (e.g., [[1,2],[3]] becomes [1,2,3]).
# uniq: Removes duplicate values.
#              4. Sorting & Reordering
# sort: Returns a sorted version of the array.
# reverse: Reverses the order of the array.
# shuffle: Randomizes the order.
# sample: Picks a random element from the array.
#              5. Utility & Conversion
# join(separator): Converts the array into a String (very useful for Flowstone's String outputs).
# to_s: Converts the array to its string representation.
# concat(other_array): Merges two arrays together.

# =========================================================
# ------------------LOOPS
# =========================================================
        @array =[] if @array == nil

        @array.each do |item|
        # Do something with item
        end

        10.times do |i|
        # Runs 10 times (i goes from 0 to 9)
        end
       
        (0..100).step(10) do |i|
        # i will be 0, 10, 20...
        end
# =========================================================
# ------------------INIT AND NILERRORS
# =========================================================       
# All full code must have init and nilerrors- this is mandatory
# All instance variables must be present in init and nilerrors

        def init
            @array = []
        end
       
        def nilerrors
            @array = [] if @array == nil
        end
# =========================================================
# ------------------SYNTAX AND CODE STYLE
# =========================================================       
# Do not write like this..
        def isInMousePoint x,y; true; end       
# Instead write       
        def isInMousePoint x,y
            true
        end     
# =========================================================
# ------------------DRAWING
# ========================================================= 
       
# In order to draw you need to create a Pen.new or Brush.new
        myPen = Pen.new @col1, 1    # Draws lines/borders
        myBrush = Brush.new @col1   # Draws solid shapes
   
        def draw v   
            drawRectangle myPen, [0,0,10,10]
        end
# DO NOT ATTEMP fillRectangle/fillEllipse---your code will be rejected. 
     
#------------------DRAWING OPTIONS-----------------------       
# drawRectangle instrument, rect
# drawRoundRect instrument, rect, corner
# drawEllipse instrument, rect
# drawPie instrument, rect, startAngle, sweepAngle
# drawPolygon instrument, points
# drawClosedCurve instrument, points     
# drawLine instrument, point1, point2
# drawArc instrument, rect, startAngle, sweepAngle
# drawCurve instrument, points
# drawBeziers instrument, points
# drawLines instrument, points       
#----------------------DRAWLING STRINGS--------------       
         def draw v
             myPen = Pen.new @col1, 1   
             font = Font.new “Arial”,1.2,”normal”
             sf = StringFormat.new
             sf.setAlignment “center”
             sf.setLineAlignment “far”
             v.drawString "Hullo", font,sf,[0,0,10,10],mypen   
         end   
#----------------------DRAWLING BITMAP--------------         
         def draw v
             @vw = getViewSize(0)
             @vh = getViewSize(1)
             sf = 12
             v.drawBitmap @bitmap,[0,0,@vw/sf,@vh/sf]             
         end   
#---------------------DRAWING BITMAP SECTION----------------
  def draw v
   @vw = v.width
   @vh = v.height   
   v.drawBitmapSection @Bitmap, [0, 0, 140, 154], [0, 0, @vw/8.0, @vh/8.0]
  end         
#----------------------DRAWLING GRAPHICS PATHS--------------       
# Graphics paths in FSR are known to be unstabe and not recommended
# Best to avoid, but if you have to, Use with caution.       
  def draw(v)

  # ---------------- RECTANGLE ----------------
  rect = GraphicsPath.new
  rect.addRectangle [-4,-3,8,6]

  v.translateTransform 20,20
  v.rotateTransform @angle
  v.drawPath @col1, rect
  v.resetTransform

  # ---------------- ELLIPSE ----------------
  ell = GraphicsPath.new
  ell.addEllipse [-4,-4,8,8]

  v.translateTransform 40,20
  v.rotateTransform -@angle
  v.drawPath @col2, ell
  v.resetTransform

  # ---------------- PIE ----------------
  pie = GraphicsPath.new
  pie.addPie [-5,-5,10,10],0,120

  v.translateTransform 60,20
  v.drawPath @col3, pie
  v.resetTransform

  # ---------------- POLYGON ----------------
  poly = GraphicsPath.new
  poly.addPolygon [[0,-5],[5,0],[0,5],[-5,0]]

  v.translateTransform 80,20
  v.drawPath @col4, poly
  v.resetTransform

  # ---------------- CLOSED CURVE ----------------
  curve = GraphicsPath.new
  curve.addClosedCurve [[0,-5],[5,-2],[3,5],[-3,5],[-5,-2]]

  v.translateTransform 100,20
  v.drawPath @col5, curve
  v.resetTransform

  # ---------------- LINE ----------------
  line = GraphicsPath.new
  line.addLine [-5,0],[5,0]

  v.translateTransform 20,45
  v.rotateTransform @angle
  v.drawPath @col6, line
  v.resetTransform

  # ---------------- ARC ----------------
  arc = GraphicsPath.new
  arc.addArc [-5,-5,10,10],0,180

  v.translateTransform 40,45
  v.drawPath @col1, arc
  v.resetTransform

  # ---------------- CURVE ----------------
  curve2 = GraphicsPath.new
  curve2.addCurve [[-5,0],[-2,-5],[2,5],[5,0]]

  v.translateTransform 60,45
  v.drawPath @col2, curve2
  v.resetTransform

  # ---------------- BEZIERS ----------------
  bez = GraphicsPath.new
  bez.addBeziers [[-5,0],[-5,-5],[5,-5],[5,0]]

  v.translateTransform 80,45
  v.drawPath @col3, bez
  v.resetTransform

  # ---------------- LINES ----------------
  lines = GraphicsPath.new
  lines.addLines [[-5,-5],[5,-5],[5,5],[-5,5]]
  lines.closeFigure

  v.translateTransform 100,45
  v.drawPath @col4, lines
  v.resetTransform

  # ---------------- ADDPATH ----------------
  p1 = GraphicsPath.new
  p1.addEllipse [-3,-3,6,6]

  p2 = GraphicsPath.new
  p2.addRectangle [-6,-1,12,2]

  p1.addPath p2,true

  v.translateTransform 60,75
  v.rotateTransform @angle
  v.drawPath @col5, p1
  v.resetTransform
end
       
#################################################       
#----------------------- VIEW------------------
################################################     
            def draw v
                @vw = getViewSize(0)
                @vh = getViewSize(1)
                # or     
                @vw = v.vidth
                @vh = v.height               
            end
#################################################

#################################################
#-------------TROUBLESHOOTING/DEBUG
################################################

# When there is a problem many hours can be wasted
# in troublshooting in the wrong areas.
# Finding the problem and going inside the problem
# is better than looking externaly.

#################################################
#-----EXAMPLE - HOW TO DRAW A RESIZABLE GRID-----
#################################################
def draw v
    @vw = getViewSize[0]
    @vh = getViewSize[1]
    @sizex = 4
    @sizey = 4
    @points = @vw/@sizex
    @points2 = @vh/@sizey
    @px = Array.new(@sizex ) { |e| e = e * @points }
    @py = Array.new(@sizey ) { |e| e = e * @points2 }

    pen_back = Pen.new @col1,0.2
           
    @grid = Array.new       
    @py.each do |y|
    @px.each do |x|       
    @grid << [x,y,@px[1],@py[1]]
    end
    end
       
    @grid.length.times do |x|
    v.drawRectangle pen_back,[@grid[x][0],@grid [x][1],@px[1],@py[1]]   
    end   
end
####################################################################
#-EXAMPLE - HOW TO DRAW A RESIZEABLE GRID WITH BLACK/WHITE CHECKERBOARD----------
#####################################################################
def draw v
    @vw = getViewSize[0]
    @vh = getViewSize[1]
   
    # SET TO 8 FOR CHESS
    @sizex = 8
    @sizey = 8
   
    @points = @vw / @sizex.to_f
    @points2 = @vh / @sizey.to_f
   
    @px = Array.new(@sizex) { |e| e * @points }
    @py = Array.new(@sizey) { |e| e * @points2 }

    # BRUSHES (Solid Fill)
    b_dark = Brush.new @col1
    b_light = Brush.new @col2
           
    @grid = []       
    @py.each_with_index do |y, row|
        @px.each_with_index do |x, col|       
            # We store [x, y, width, height, color_toggle]
            color_toggle = (row + col) % 2
            @grid << [x, y, @points, @points2, color_toggle]
        end
    end
       
    @grid.length.times do |i|
        # Pick light brush if toggle is 0, dark if 1
        brush = (@grid[i][4] == 0) ? b_light : b_dark
       
        v.drawRectangle brush, [@grid[i][0], @grid[i][1], @grid[i][2], @grid[i][3]]   
    end   
end
#################################################
#---------------USEFUL INFO----------------------
################################################

# This API has successfully created,
# 1. Game of Life
# 2. Asteroids
# 3. Tetris
# 4. Space Invaders
# 5. Snakes and Ladders
# 6. Minesweeper           
# 7. Reversi 
# 8. Combat
# 9. Battleship
# 10. Snooker
# 11. Pacman
# 12. Pinball
# 13. Checkers
# 14. Breakout
# 15. Knob maker
# 16. Chess
# 17. Chess_Pro
# 18. Chess_3
# Do not deviate from this API.
# FSR is a HOSTILE enviroment, if there's anything wrong,
# we get red errors.
# I have 20 years experience coding FSR. Listen to my instructions.
# Do not deviate from this API.
########################################################
Attachments
Schematic_FSR BRAIN API.fsm
(4.52 KiB) Downloaded 5 times
billv
 
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Return to General

Who is online

Users browsing this forum: No registered users and 17 guests