Class Game
Authors: Twb6543
Version: 1.2
Type: Scripting Tool and Game Utility
Key Term: Scripting Tool
IntroductionQuoteCreative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
( http://creativecommons.org/licenses/by-nc-sa/3.0/ (http://creativecommons.org/licenses/by-nc-sa/3.0/) )
You are free:
to Share - to copy, distribute and transmit the work
to Remix - to adapt the work
Under the following conditions:
Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
Noncommercial. You may not use this work for commercial purposes.
Share alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
- For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
- Any of the above conditions can be waived if you get permission from the copyright holder.
- Nothing in this license impairs or restricts the authors moral rights.
This adds $game to the game and allows for registration and requirements for scripts...
This adds mostly the same features that RGSS had for registration and requires...
Features
- register(name,version)
- script?(name)
- version?(name,version,returnversion) // returnversion is 1 for return of version (return version number)
- deletekey(name)
- updateversion(name,version)
- clear
ScreenshotsScreenshots N/A
DemoNo Demo just plugin and play
ScriptPut this script above ALL custom scripts unless otherwise specified
//Download a .txt document of the script here // (http://dl.dropbox.com/u/29385297/Class%20Game.txt)
#===============================================================================
# Aliasing
#===============================================================================
# Alias the neccessary methods to change Game to $game // Is currently here do
# to strange errors if I place it anywhere else (might not happen to others)...
#===============================================================================
class Scene_Title < Scene_Base
alias :old_create_game_objects :create_game_objects
def create_game_objects
old_create_game_objects
$game = Game.new
end
end
class Scene_File < Scene_Base
alias :old_write_save_data :write_save_data
def write_save_data(file)
old_write_save_data(file)
Marshal.dump($game, file)
end
alias :old_read_save_data :read_save_data
def read_save_data(file)
$game = Marshal.load(file)
old_read_save_data(file)
end
end
#===============================================================================
# Class Game Ver 1.2
# by Twb6543
#===============================================================================
# Adds registeration and script? commands
# Mimics RmXp commands of register and requirements
# Adds has $Scripts with layout script => version ...
# Use $Game.command to carry out a command (replacing command with a command)
#===============================================================================
#===============================================================================
# Commands:
# - register(name,version)
# - script?(name)
# - version?(name,version,returnversion) // returnversion is 1 for return of
# version (return version number)
# - deletekey(name)
# - updateversion(name,version)
# - clear
#===============================================================================
#===============================================================================
# - Versions are automatically use 1.0 for base version you may change this on
# line 67 , 79, 107...
#===============================================================================
class Game
def initialize
$Scripts = {}
register("Game",1.2)
end
def register(name,version=1.0)
$Scripts[name] = version
end
def script?(name)
return $Scripts.has_key?(name)
end
def version?(name=1,version=1.0,a=0)
if a == 1
return $Scripts[name]
else
if $Scripts[name] >= version
return true
else
return false
end
end
end
def deletekey(name)
$Scripts.delete(name)
if script?("Game") != true
register("Game",1.2)
end
end
def updateversion(name,version=1.0)
$Scripts.delete(name)
$Scripts[name] = version
end
def clear
$Scripts.clear
$Scripts["Game"] = 1.2
end
end
InstructionsSee script... (POST ABOVE ALL OTHER CUSTOM SCRIPTS)
Usage of commandsRegister: $game.register("Test",1.0)
// Registers the script
Script?:if $game.script?("Test") == true
$game_variables[1] = 1
end
// If script Test is registered then Game_Variables 1 is set to 1
Version?:if $game.version?("Test",1.0,1) >= 1.0
$game_variables[2] = 1
end
// If script version test is 1.0 or over then Game_Variables 2 is set to 1
if $game.version?("Test",1.0) == True OR if if $game.version?("Test",1.0,0) = True
$game_variables[2] = 1
end
// If script version test is 1.0 or over then Game_Variables 2 is set to 1
DeleteKey:$game.deletekey("Test")
//Will delete the info on script Test from $Scripts
UpdateVersion:$game.updateversion("Test",1.1)
// Sets the version information about Test, in $Scripts, to 1.1
Clear:$game.clear
//Clears $Scripts
ScriptersI recommend using a style like this to register your script in the initialize def...
if $Scripts["Game"] >= 1.2
$game.register("Script",Version)
else
print "Class Game is not found please install correctly Class Game 1.2"
print "Visit http://forum.chaos-project.com/index.php/topic,9831"
end
CompatibilityShould be compatible with most scripts.
Credits and Thanks
- Twb6543
- Enterbrain - for original in RMXP
Author's NotesNothing really to add - Sorry for the section at the top but really it's the only thing that makes it work for my pc... You may have to use $SCRIPT = SCRIPT.new for the commands to register (You may have to run your script). To all scripters their is little comments but all commands should be fairly easy to understand.
Change Log1.2
- Registered the script itself to correct version
- re-register if the key is deleted
1.1
- Registered the script itself
- Re-Register the script if $Scripts is cleared => Does not re-register if the key is deleted
I placed your usage commands in the instructions where they go. If you would like to add updates either add a new header, or list the updates under the spoiler for your script.
Sorry, I just find it easier to edit if it is a different post... // Less Text to go through..
Version 1.1 will be up in a minute...
Change Log
- Registered the Script itself so it can be checked for see the scripters notice above.
- Re registers the script if cleared // Have not done delete key as there is no real point at the moment //
- Also changed thread title due to spelling error...
I would like to point out that this is useless. You don't need an entire script to keep track of scripts you have. You just set a global variable to know whether a script is defined or not. Look at most of Blizzard's scripts, example Blizz-ABS. He has a variable $BlizzABS. Having a script to keep track of them all is a bit useless.
Quote from: game_guy on June 04, 2011, 11:18:37 am
Having a script to keep track of them all is a bit useless.
*cough* SDK *cough*
SDK is like that as Blizzard pointed out, but the main purpose of this script was to replicate a few commands from XP that I thought were missing from VX, this being the require and register command...
The SDK still sucks and shouldn't be used. There is no need to have one script keep track of them all. And the way you're doing it, it looks like Game_Class gets saved. So it could save a script, later it would be removed, load up the save game and it'll act as if it still has it.
Practically yes, I still need to do some work on it, but the main purpose of it is just so the scripter can check if loads of different scripts are installed... lets say theirs a compatibility problem in one script with 5 overs rather than using global variables for all of the scripts all that's need is one script (if all scripts register). Currently I need to tweak it a bit but as a base you can use it to warn user of compatibility problems, say if the user has forgotten to install a script, and also do some simple functions easily (e.g. run a fake support script, if script a requires script b, but script c can do the same job as b then they can rewrite it / fake a script (I know this can also be done as a variable))
Yes, but the only way this would ever work is if every scripter either did this from the start, or went back and updated all their scripts.
This is really no different than a SDK log, which was really just used so people could feel cool putting a fancy header to their scripts. It is not hard to test if a script is present, even without using global variables or "registering" it. A simple "defined?(Some_Class)" works very well for the 3% of the time it is needed. For the most part, the global variables a scripter might add are usually used by their own other scripts, or smaller add-ons by others, in which case they already know what it is. 95% of scripts have no need to "register" as it is just a waste of memory, since there is really no need to check if is present or not. On top of that, the person who wrote the script can simply raise their own exception if a script is not found. I did just this in Zer0_CMS. It requires either ATES or CCTS, so made a simple if..end to make sure one of the two were there, and if not, tell the user that one of them has to be.
sigh really I give up, I'll keep a back copy of the script, so can a mod just delete the thread seeing as no one really wants this...
This is a really good script! This can help me out a lot! Thanks for making it.
This is different from the SDK log. (Checking for the existence of the SDK log and registering if it's there is really nothing more than a minor nuisance)
The fact that the registered scripts are saved into the save files means that you use that knowledge to do maintenance on saves made with older versions of scripts or saves that do not have a new script you added.
There are several scripts which renders old files unusable. You can use this script to help you load those saves.
*hugs*
this is a very good point Zeriab. I never really considered that use. from that perspective it's also good if your planing on making a game the supports modding, in such a case keeping track of scripts used in a save file would be endlessly helpful.
Finally someone actually got it, I actually realised this after every one said it was totally pointless, seeing as nobody really took interest in this much I decided not to post any updated information about it. If anybody wants to use any part of this feel free, I'm currently trying to write a version based off this for a game I'm making.
The version I'm now writing will hopefully be used for the patch system allowing previous saves to be updated to the new game version hopefully stopping the save from breaking.