Improving $imported (7/23 Update: Start suggesting keys/values!)

As a scripter, what do you think of this idea?


  • Total voters
    23

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I think some of the key/value [pairs are a great idea and would be happy to adopt such things for my own scripts; however, i also think some of the proposed k/v's are completely unnecessary.


Quite a few of them are information that would generally be contained within a script header, such as author, version, description etc.
You cannot enforce how people want to write headers.


If you force them to write them as ruby, then you can at the very least parse it as ruby.

Also, just an afterthought, but...


If we started adding all this extra data into the $imported variable, wouldn't it cause performance loss to some degree ?


I mean... Many people have already complained previously about having to use $imported and how $imported is just data 'lying around doing nothing'.
Are we talking bytes of "wasted" memory and nanoseconds of start-up time?
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
You cannot enforce how people want to write headers.

If you force them to write them as ruby, then you can at the very least parse it as ruby.

Are we talking bytes of "wasted" memory and nanoseconds of start-up time?
Indeed, one cannot enforce how to write a header. I guess if there was a 'standard' way of doing it, that most everyone incorporated, it would be highly useful for raising compatibility. But unless everyone adopted it, I dont really see any advantage - other than holding more detail in the $imported. Which - if you where the only one using it, would only cause yourself more workload...

Yea, i was referencing those people who enter 'rage mode' at the thought of a few extra bytes floating around :p
 

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
I got bored and made a simple version system using a custom version object.

Code:
class VersionObject  attr_accessor :current_version  attr_accessor :versions  def initialize(name, current_version)    @current_version = current_version    @versions = [current_version]  end    # This is called when your object already exists.  def add_version(version_int)    @current_version = version_int    @versions.push(version_int)  end  # Check if the currently installed script is the correct verison.  def match?(checked_version)    return (@current_version == checked_version)  end  # Check if the currently installed script is newer   # than the one required in the function call.  def older?(checked_version)    return (@current_version < checked_version)  end  # Check if the currently installed script is newer   # than the one required in the function call.  def newer?(checked_version)    return (@current_version > checked_version)  end  end$imported = {} if $imported.nil?if $imported["SomeRandomScript"].nil?  $imported["SomeRandomScript"] = VersionObject.new("SomeRandomScript",1000)else  $imported["SomeRandomScript"].add_version(1000)end$imported = {} if $imported.nil?if $imported["SomeRandomScript"].nil?  $imported["SomeRandomScript"] = VersionObject.new("SomeRandomScript",1001)else  $imported["SomeRandomScript"].add_version(1001)endif !$imported["SomeRandomScript"].nil?  p "1.0.0.2 match? " + $imported["SomeRandomScript"].match?(1002).to_s  p "1.0.0.2 newer? " + $imported["SomeRandomScript"].newer?(1002).to_s  p "1.0.0.2 older? " + $imported["SomeRandomScript"].older?(1002).to_sendclass TestClassA    def initialize    @bacon = "tasty"  end  endclass TestClassB < TestClassA  attr_reader :bacon    @test = $imported["SomeRandomScript"]  if @test.match?(1001)    def initialize      @bacon = "bacon"    end  else    def initialize      @bacon = "taco"    end  end  end$durka = TestClassB.newp $durka.bacon
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
imo, thats seems somewhat unnecessary.
 

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
imo, thats seems somewhat unnecessary.
Its not like you need to organize your classes like that, it was just an example.  A fairly lazy one.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
out of curiosity, why did you make durka a global variable

$durka = TestClassB.newp $durka.baconwhen a local variable would have worked just as well.

Code:
durka = TestClassB.newp durka.bacon
 

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
out of curiosity, why did you make durka a global variable

$durka = TestClassB.newp $durka.baconwhen a local variable would have worked just as well.

durka = TestClassB.newp durka.bacon
I usually program in globals when I'm making examples of objects to access elsewhere.
 

PK8

I sense there's something in the wind...
Veteran
Joined
Mar 17, 2012
Messages
1,220
Reaction score
152
Primarily Uses
Correct. That is unnecessary.


Writing a script that users are required to install in order to check for the version of a script not only makes compatibility/version checks far more complicated than it needs to be, it really runs in contrast as to what $imported is all about. The beauty of $imported, imo, is that none of any of the implementations are required but recommended.


We're walking a very fine line between the two when it comes to that.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
@PK8 - has any key/hash combo been settled on?
There are some elements of this idea I really like and would be happy to incorporate into my own scripts :)

Although, cause I dont use the imported global variable I could just use the elements I want in my own global variable :p
 

PK8

I sense there's something in the wind...
Veteran
Joined
Mar 17, 2012
Messages
1,220
Reaction score
152
Primarily Uses
I would say anything from here should be pretty safe to use. I doubt any of them are getting changed anytime soon.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
Guess i will choose a few i like then :p
 

Zeus81

Veteran
Veteran
Joined
Mar 17, 2012
Messages
164
Reaction score
150
First Language
French
Primarily Uses
The only thing I need to make my scripts compatibles all together despite the fact of knowing that the script is here is the script order.
Some snippets of code I use in several scripts must be defined only once.

Then I use :

$imported[:name] ||= __FILE__if $imported[:name] == __FILE__  ...end__FILE__ returns the script id in the scripts list.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top