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

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?
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 😛
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
imo, thats seems somewhat unnecessary.
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.
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
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.
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.
@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 😛
I would say anything from here should be pretty safe to use. I doubt any of them are getting changed anytime soon.
Guess i will choose a few i like then 😛
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.

Original thread: https://forums.rpgmakerweb.com/threads/improving-imported-7-23-update-start-suggesting-keys-values.30078/