Web script loading system

Web script loading system.
Older Method

If you want to store the file locally use the Older Method

Spoiler
What does it do?
All it does is load a script from a website (pastebin, github or something) and caches it into a local folder.
 
What do you need?Instructions

  • Create a folder named "Web" in the directory of your project
  • Paste that into your project.
  • Create a new script section.
  • Write or copy your script inside of your file hosting site (github, etc) for this example I will just enable a switch.
  • This is how the file should look in github (for this example)
  • QRmCrHW.png
  • Okay in your script window write your GET request: for my example it should look like this:
begin http_reply = HTTP::get('', 'raw.githubusercontent.com','/Heark/rgss3/master/switch.rb')replace raw.githubusercontent.com with what ever site you are using, if it was pastebin it should be:

begin http_reply = HTTP::get('', 'pastebin.com','/raw.php?i=msA8g6bV')In our script window we should have this so far:

begin http_reply = HTTP::get('', 'raw.githubusercontent.com','/Heark/rgss3/master/switch.rb')If you do not have this, turn back now.
 
Next, we create the 'out.rb' file:
add this simple line:

out_file = File.new("Web/out.rb", "w")next we want to write our webcalled script to 'out.rb';
 
add this simple line:

out_file.puts(http_reply)next add this

rescue IOError => e#...ensureout_file.closeendFixes an error that occurs.
next add:
 

if File.exist?('Web/out.rb')File.delete('Web/out.rb')endWe add this because if the the file is already in our folder we want to delete it so it can pull the newest version.
 
So our Script Window should look like this:

if File.exist?('Web/out.rb')  File.delete('Web/out.rb')endbegin  http_reply =  HTTP::get('',  'raw.githubusercontent.com','/Heark/rgss3/master/switch.rb')out_file = File.new("Web/out.rb", "w")#...out_file.write(http_reply)rescue IOError => e#...ensureout_file.closeendYou could add many scripts just change the name of out.rb to whatever you want
 
Finally call the script in game or in the script window using the script call:

load_script("Web/out.rb")
  • First get Dekita's basic HTTP processing script.
  • Get all necessary files (DLLS and what not).
Write this in your script window:

def load() return eval HTTP::get('', 'raw.githubusercontent.com', '/Heark/rgss3/master/switch.rb')endThen use the call:

load()Terms of Use:
For non-commercial use only, Dekyde Studios forbids use in commercial projects
Hime requests that you speak to him.
 
Credits
Jet
Tsukihime
Dekyde Studios / Dekita
Yuuta Kirishima
Credit the above people.
Very nice!

It's usefull for people who want to do some kind of "update system", like I did on my game. This way, if you fix something in a script on your game, the players won't have to redownload the whole Game.rgss3a file.
Yes! 🙂 I formed it because I wanted to create a Mystery Gift(If you've played pokemon you know what this is) like system in which an event only appears during special Events Like on Christmas the player can talk to certain NPC to give you a gift.
If you're using it only to load a script from the web, and not caching the script/checking for latest versions. Basically, if you're trying to do the exact thing listed in the topic, it can be shortened down to

Code:
eval HTTP::get('', 'raw.githubusercontent.com', '/Heark/rgss3/master/switch.rb')
Yes but this caches the file so it can be called for later use.


It stores the data it gets from github into a local rb file.


Sorry for not being to clear in the topic.
Right but, your code right now would re-download the file every time at boot, so saving it as a file seems pointless. It might even be better to just hold it in memory if it's a script that will be called more than once per boot.
def load() return eval HTTP::get('', 'raw.githubusercontent.com', '/Heark/rgss3/master/switch.rb')endIf I don't want to cache it I could just call this, but the file wouldn't be stored locally and I won't be able to change it in-game.

You are right, if you store it locally you won't be able to encrypt your game, I'll update the topic.

Original thread: https://forums.rpgmakerweb.com/threads/web-script-loading-system.41401/