Help needed with .exe file issues.

For general discussion related FlowStone
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Help needed with .exe file issues.

Post by tulamide »

Spogg wrote:
tulamide wrote:When you use loadState and saveState in Ruby, it makes use of the Marshal module. You can use it as well. It generates a binary string, which you can simply save with the File class/IO class and later load in.

Usage:

Code: Select all

result = Marshal.dump([myArray, myVar, "some string", in_short_any_object])
some_array, some_var, some_string, some_obj = Marshal.load(result)
Ooh that’s interesting!
So if I understand correctly, Tim could stay completely in the Ruby world…?
If that's a requirement, then yes. But you can use this also to save everything that you are able to input to Ruby. Marshalling is more than just saving some numbers, though. It makes binaries of every object fed to it, so that it can be restored exactly as it was. For that it scans through all references to objects, to "paint the whole picture". For example, if you have an array filled with arrays of arrays, all of them will be saved to the binary string. Imagine it like a DAW snapshot - it will load all plugins, set them all to the last state, load the mixer settings, and so on.

But if understood, it's a very useful instrument of restoring the state of objects and therefore saving data.
"There lies the dog buried" (German saying translated literally)
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: Help needed with .exe file issues.

Post by Spogg »

@tulamide
That’s remarkable, to say the least! :o
Although I’ll never use it myself, I find that really impressive.
TimC
Posts: 9
Joined: Sat Dec 24, 2022 12:24 pm

Re: Help needed with .exe file issues.

Post by TimC »

Hello tulamide, I've put together code which works (without using Marshal) but it involves a lot of conversion to strings etc.

I've tried to implement Marshal as you suggest, but cannot get any of it to work!
I have created a Class Button, which includes data about what I want to be drawn, how to respond to clicks etc.
I make a collection of these in an array, @buttons. This all works
I tried to dump @buttons with

File.open("D:\FILES - LIVE\KEYBOARD\KS WIP\K3M","w+") do |f|
@save=Marshal.dump(@buttons,f)

and restoring it by triggering an input in def events
if i==9
#Marshal try
@buttons=Marshal.load(@save)
end
As I understand it, File.open should create a file if the name doesn't exist, but I'm not even getting a file created, so the dump method does nothing, and of course there's nothing for the load to load.

I think, in theory, the Marshal method would be better and more reliable, so I'd apprecate you pointing me in the right direction!

Tim
Post Reply