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 A.I. to understand FS RUby

For general discussion related FlowStone

Training A.I. to understand FS RUby

Postby billv » Tue Jan 27, 2026 8:50 pm

I was working on a bouncing ball and I was using ChatGBT to help me write the code. It took me the whole day,
ChatGBT had about 30 attempts before we got it right. ChatGBT is very smart, but with FSRuby, it's really dumb.
And to make things worse, if you start a fresh chat, it does not remember any previous chats.
The solution was simple, i told Chat to go through the entire thread, collect all stuff it learnt
that it didn't know, compress it all down to one rubyedit, so I can then copy and paste into new chats,
thereby giving ChatGBT a FSR code BRAIN, saving a shitload of time. I wasn't really happy with the result.
So after seeing the potential, I decided to this properly.
I uploaded a shitload of FSR Code. The Ai is behaving perfectly, taking only the logic that it needs,
and then breaking down everything that it learns.
The end result, is one simple rubyedit, filled with all the FSR code, that ChatGBT, dosn't know.
Just Paste the rubyedit into the start of your chat, and WHAM!...your A.I. is now FSRuby smart.
I Tried it with Conways game of life...took 3 attempts but it worked. Download at Discord.
Code: Select all
=begin
FLOWSTONE RUBY BRAIN (REAL WORLD)

Core Environment:
- FlowStone Ruby is NOT real Ruby.
- It is a real-time modular VM.
- Everything is event-driven.
- Think hardware, not software.
- No global loops, no blocking, no threads.

Golden Rules:
- event signature must match module type:
  * def event i,v,t   (timed modules)
  * def event i,v     (UI / controls)
- Wrong signature = crash or silence.
- Never assume standard Ruby works.

Time & Scheduling:
- scheduleMethod must ALWAYS use time, never Time.now.
- Scheduling without t or time = RubyEdit crash.
- Use:
    scheduleMethod "method", time + step
- Never recursive loops without scheduleMethod.
- Timers must self-reschedule.

State Model:
- All controls are state machines.
- State is stored in instance vars only.
- Rendering never owns logic.
- One function must be the truth source:
  (eg selectionChange, offsetChange, tick)

Mouse System:
- captureMouse locks control until release.
- mouseMoveCaptured is real-time stream.
- mouseMove is hover only.
- releaseMouse ALWAYS on mouse up.
- Right click often used for delete/reset.
- isInMousePoint usually returns true.

UI Geometry:
- getViewSize gives drawable area.
- Never trust v.width alone.
- All hit testing is manual.
- Grid systems always use:
    @grid = [x,y,w,h]
    @gridval = [x..x+w, y..y+h]

Drawing:
- draw only paints.
- Never mutate logic in draw unless cached.
- redraw triggers draw.
- draw runs constantly.

Never put heavy logic in draw.

Arrays:
- Always guard nil:
    @array=[] if @array==nil
- FlowStone will happily pass nil everywhere.
- nilerrors pattern is mandatory.

Mouse Drawing (Pen Tool):
- Real-time drawing uses integer stepping.
- Never use float micro movement.
- Always cast to to_i.
- Use uniq on arrays to avoid explosion.

Knobs:
- Value always 0.0–1.0.
- Mouse movement is relative.
- SHIFT = fine adjust.
- Always clamp:
    @value = [[@value,1].min,0].max

Buttons:
- Down = visual + trigger.
- Up = reset visual.
- Output impulses, not toggles.

Bitmap Buttons:
- Use state strings:
  '', 'over', 'down', 'disabled'
- Visual system reads state, logic never draws.

Scrollbars:
- Two coordinate systems:
  * real content
  * virtual content
- Handle size = ratio of real/virtual.
- offsetChange is single truth function.

Selectors:
- One core function:
    selectionChange(index)
- Everything must funnel through it.
- MIDI, mouse, default, next/prev all call it.
- Never set @oIndex directly.

DropLists:
- Are external UI.
- Control only consumes callbacks.
- Never draw your own menus.

MIDI:
- Red pins accept ONLY Midi objects.
- Format:
    Midi.new(status, channel, note, velocity)
- NoteOn = 144
- NoteOff = 128
- Never toggle MIDI.
- Always fire impulse:
    output midi_on
    output midi_off, t + delay
- Zero velocity = crash.
- Every wall hit = new note.

Sequencers / Clocks:
- Internal clock is integer.
- Use -1 for stopped.
- Wrap manually:
    @clock = 0 if @clock == steps
- Host clock is separate.
- Never allow step <= 0.

Random:
- rand always used as:
    rand(0..1)
- Never rand without range.

Graphics Scaling:
- Internal coordinates should be integers.
- Canvas scaling is visual only.
- Physics must stay in 0–127 or similar.
- Floats in motion = freezes.

Reflection Math:
- For bouncing:
    pos = (2*max) - pos
- Prevents corner lock.

Saving State:
- saveState returns single primitive.
- loadState restores and triggers logic.
- Never save arrays unless required.

Mental Model:
- Modular synth, not program.
- Events > loops.
- Impulses > toggles.
- Geometry > widgets.
- States > objects.
- Rendering is skin only.

If it looks right but doesn’t behave right:
It is wrong.

If it behaves right but looks wrong:
It is correct.

END FLOWSTONE BRAIN
=end

PS: If one of the Guru's had a go at this, well get a much better result.
billv
 
Posts: 1162
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Return to General

Who is online

Users browsing this forum: No registered users and 19 guests