Support module for scripters

● ARCHIVED · READ-ONLY
Started by Holy87 7 posts View original ↗
  1. Universal Module
    v1.2.6, by Holy87

    Features

    Provides more functionalities for scripters (and it is used in a lot of my scripts), let's see what you can do:

    System communication

    You can obtain the screen resolution, Pictures/My Documents/Music/Video/Desktop folders, Windows user account name, Windows version and language, and changing the game window's width and height.

    Internet

    You can downlaod files and get response with async methods: you don't have to check when the download is terminated, just set the method that will be automatically called when the file will be downloaded.

    You can also open the system default browser to a specific URL!

    Universal data that not depends on savegames

    You can store variables and switches that not depend on savegame, but are universal: for example, if I want unlock an "Extra" option in the title screen when the player completes the game. You can do that with this!

    String options and crypting

    You can encode/decode a string in ROT13 or Base64, and also get a random string if you want.

    Other functionalities

    Version class: You can create a version class with major, minor, build and revision informations (like 1.0.15.3). You can also compare versions and, obviously, set a game version creating a version.ini file in the project root.

    println method: like p and print methods, but automatically adds a newline in the console.

    How to Use

    Place the script under Mateirals and above Main.

    Code Examples:

    How to get system Informations

    print Win.username #=> "Francesco"print Win.version #=> 10.0print Win.getFolderPath:)dskt) #=> "C:/Users/Francesco/Desktop"print Win.resolution #=> [1024,730]. Note that it's not all the display resolution, but only the part#of the screen not covered by the taskbar, so you know how big you can resize the game window.Internet and HTTP

    Async method are easy-to-use, but by default are avaiable only in the Scene and Window class. You can make it avaiable in other classes including the Async_Downlads module (see in the script)

    Let see how they work. For example, I want to download automatically a new picture for the title screen. What I've to do is:

    class Scene_Title < Scene_Base  def download_new_title    download_async("http://myhost.com/title_wallpaper.jpg", method:)title_downloaded), "Graphics/Pictures/")  end   def title_downloaded #launched automatically when the download is completed    @sprite2.bitmap = Cache.picture("title_wallpaper.jpg")  endendHow to open the browser to a web page:

    Browser.open("www.google.com")Using universal data

    The universal data (variables and objects) are stored in the Game_Settings.rvdata2 in the project's root. Let's see how to use them. You can use the $game_settings instance.

    $game_settings[:game_completed] = trueThe data will be automatically saved when the value changes, so I can read the data using the same methodology

    unlock_extra if $game_settings[:game_completed]String encoding

    The Base64 codification is useful for making secure communication between client and server.

    print Base64.encode("Hello World") #=> "sgvsbg8gv29ybgq="Using Base64.decode method you can return to the normal string.

    Version Class

    You can make a game version (to show in the title screen or for use in other scripts) just creating a version.ini file in the project's root, and writing inside a number with one or more digits, like

    1.2.50.3where

    1 is the major release, 2 the minor release, 50 the build and 3 the revision.

    You can call the game version from script using

    print $game_system.game_version #=> "1.0" by default, if no version.ini file is createdThis method returns a Version object file, that has the major, minor, build and revision public attributes, but with the .to_f method returns a formatted string.

    You can create a new version object by using

    new_version = Version.new("1.3.5.0")The versions are also comparable, then you can do this

    if new_version > $game_system.game_version  print "A new update is avaiable"endThere's much more described in the script documentation.

    Download

    You can download the script from GitHub.

    Blog's page

    FAQ

    Q: Is this script for everyone?

    A: A lot of my script require this module, then you have to copy and paste in your project. You can also use this script for your scripts, but it requires scripting skills.

    Q: Can I use this script for my commercial project?

    A: Yes, you can. all my scripts are distributed under CC-BY license. You just have to credit me.
  2. Very nice, there's a lot of cool stuff in there.

    I'd recommend adding the .rb file extension on your github file, that way it'll be automatically highlighted by github, making it easier to read.
  3. Hudell said:
    Very nice, there's a lot of cool stuff in there.

    I'd recommend adding the .rb file extension on your github file, that way it'll be automatically highlighted by github, making it easier to read.
    Thanks, I've forgot that :D
  4. Shhhh don't tell anyone about  ruby's 'puts'

    wich is exactly:

    def puts(*args) args << '\n'   print(*args)endAnyway, this utilities are very practical :p
  5. Ramiro said:
    Shhhh don't tell anyone about  ruby's 'puts'

    wich is exactly:

    def puts(*args) args << '\n'   print(*args)endAnyway, this utilities are very practical :p
    Thanks, but println is more familiar to me :D
  6. Agreed - there are some nice features in there..

    I must say though, you should really consider moving to the DL class to handle your api calls, rather than Win32..

    Heres an idea on how to go about that. :)

    Code:
    def get_user_name  @dll ||= DL::dlopen('advapi32')  @fun ||= DL::CFunc::new(@dll['GetUserName'], DL::TYPE_LONG)  fun_return_val = @fun::call([    DL::CPtr[name = " " * 128]::to_i,    DL::CPtr[size = "128"]::to_i,  ]::compact)  if fun_return_val == 0    return raise("Error getting user name")  end  name::unpack("A*")::firstend
  7. ■ ᴆᴈᴋᴉᴦᴀ ■ said:
    Agreed - there are some nice features in there..

    I must say though, you should really consider moving to the DL class to handle your api calls, rather than Win32..

    Heres an idea on how to go about that. :)

    def get_user_name  @dll ||= DL::dlopen('advapi32')  @fun ||= DL::CFunc::new(@dll['GetUserName'], DL::TYPE_LONG)  fun_return_val = @fun::call([    DL::CPtr[name = " " * 128]::to_i,    DL::CPtr[size = "128"]::to_i,  ]::compact)  if fun_return_val == 0    return raise("Error getting user name")  end  name::unpack("A*")::firstend
    Thanks, honestly I didn't know that I could use the DL class! I will work to substitute them. ;)