Author Topic: script compiling?  (Read 1851 times)

Offline diagostimo

  • Ethereal Devastator
  • ****
  • Posts: 257
  • LV: 20
    • View Profile
script compiling?
« on: February 02, 2013, 11:28:15 AM »
hey guys, I was wondering if anyone could offer me any insight how to compile multiple scripts into one file, like how in RPG maker, all the scripts are compiled within Scripts.rxdata, I was just wondering as I am creating my own engine sort of thing and it would be really handy to be able to have one master file that I load to get to all my scripts, same for editing them, I would probably go about making some sort of script editor that opens up the file and lets me write to it, if anyone knows how I would pull this sort of thing off that would be great, im writing in java to be specific, so maybe there is something out there that already achieves this. 

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19982
  • LV: 648
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: script compiling?
« Reply #1 on: February 02, 2013, 11:53:48 AM »
They are not really compiled, they are just zipped. You can load the scripts from the file just like any other rxdata file using Marshal (you will get a Hash instance if I remember right) and then using Zlib::inflate to decompress the strings.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline diagostimo

  • Ethereal Devastator
  • ****
  • Posts: 257
  • LV: 20
    • View Profile
Re: script compiling?
« Reply #2 on: February 02, 2013, 12:57:37 PM »
ok cool, i did try marshal loading it but I just got a load of gobbledy goop, but knowing I need to use Zlib that helps, just tested that out in RPG maker xp and I see that everything is inside an array, so I am guessing the structure is like this:
[[script], [script], [script]]
where each script is is separated into lines(strings) right?
that is what I am guessing as the print screen console is pretty limited, I also noticed that the from the first 2 elements of the script, the first was an integer, and the second was the name, just wondering what the integer was for really? as its a high number.
that actually makes it really easy now as I can totally see how the editor separates and allows you to edit these, I guess my main question now is how does the engine turn these into scripts? like how would I convert the strings into a program?

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19982
  • LV: 648
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: script compiling?
« Reply #3 on: February 02, 2013, 03:42:19 PM »
Here, just take this:

(click to show/hide)

This is the external Ruby script that I use to open a Scripts.rxdata and extract all scripts into files. Take out the code for extraction and have fun with it. You won't need "require 'zlib'" if you are using this from within RMXP.

The structure is like this:

[[INT, NAME, COMPRESSED_SCRIPT], [INT, NAME, COMPRESSED_SCRIPT], ...]

I can't remember what the first value is supposed to be.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline diagostimo

  • Ethereal Devastator
  • ****
  • Posts: 257
  • LV: 20
    • View Profile
Re: script compiling?
« Reply #4 on: February 03, 2013, 02:04:19 AM »
thanks, that's awesome but what I meant is, how would I run the scripts from the file like when the game runs, say I need to use a class for something outside rmxp, instead of making a copy of the script, how could I load all the classes from there strings, like requiring all the scripts in the file, would I use eval or is eval just to execute code?
edit:
ok i tryed using eval, and it let me use the classes fine, but is this a correct way to do it? also thanks you have helped out loads i thought it would have being way more complicated  :D
« Last Edit: February 03, 2013, 02:08:30 AM by diagostimo »

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19982
  • LV: 648
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: script compiling?
« Reply #5 on: February 03, 2013, 05:01:08 AM »
Simply use one of these two:

Code: [Select]
load 'filename'
Code: [Select]
require 'filename'
eval() works, too, but these two are the proper practice to do it.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline diagostimo

  • Ethereal Devastator
  • ****
  • Posts: 257
  • LV: 20
    • View Profile
Re: script compiling?
« Reply #6 on: February 03, 2013, 07:45:04 AM »
what so i could just do:

Code: [Select]
require 'Scripts.rxdata'

and that would load all the classes out of the strings? i have tried that but that does not work,
here is an example of what I am doing at the moment via the ruby interpreter:

Code: [Select]
require 'zlib'
begin

File.open("Scripts.rxdata", "rb") {|f|
file = Marshal.load(f)
inflated = Zlib::Inflate.new.inflate(file[0][2])
eval(inflated)

puts inflated
}

$game_temp = Game_Temp.new
    
puts "=============================================="
puts $game_temp.choice_start
gets


end

instead could I do each require/load on the inflated string instead of using eval?
« Last Edit: February 03, 2013, 07:46:40 AM by diagostimo »

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19982
  • LV: 648
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: script compiling?
« Reply #7 on: February 03, 2013, 01:48:16 PM »
No, require and load are for text files. If you want to load the scripts for Scripts.rxdata, then this script you made with eval works fine.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.