what's the equivalent of those Ruby line in JS?

Hi I'm converting a script I commissionned from @Shaz and I liked a lots and I add permission in the past to convert it to MV but I still struggle to convert it.


What's the equivalent for those lines in JS?


$data_weapons.compact.each { |w| w.build_equipment_restrictions }

@restrict_users = /<user (.*)>/i.match(line)[1].scan(/\d+/).collect { |i| i.to_i}

@restrict_users.empty? || @restrict_users.include?(actor_id)

equips.compact.inject(super) {|r, item| r += item.user_params(@actor_id, param_id) }


do you know how I could "transfert" those methods to MV? 


thanks for your further answer 🙂  
Ugh!  Regular expressions and injecting.  My two favourite subjects (not!)


I don't know what the conversions are.  Hopefully there'll be a JS pro who can tell you.
Ugh!  Regular expressions and injecting.  My two favourite subjects (not!)


I don't know what the conversions are.  Hopefully there'll be a JS pro who can tell you.

yeah I'm searching some work around for make the User Restriction plugin conversion you made for me in Vx Ace....and I can say this not easy XD
I can't really remember that script, but I'll have items restricted by users so I imagine I'll have to do something similar, when I get around to it.
I can't really remember that script, but I'll have items restricted by users so I imagine I'll have to do something similar, when I get around to it.

it's that haha but SO small but so hard to do! because simply the classes areq inexistant in MV and are configurated differently lol.


The regexp part is not that hard to do it's easy to eval it or even to extends it the problem is that how the  difference is big.

Spoiler
Code:
module DataManager
  class << self
    alias shaz_equip_restrict_load_database load_database
  end
 
  def self.load_database
    shaz_equip_restrict_load_database
    build_equipment_restrictions
  end
 
  def self.build_equipment_restrictions
    $data_weapons.compact.each { |w| w.build_equipment_restrictions }
    $data_armors.compact.each { |a| a.build_equipment_restrictions }
  end
end
 
class RPG::EquipItem < RPG::BaseItem
  def build_equipment_restrictions
    @restrict_users = []
    @restrict_minus = 0
 
    note.split(/[\r\n]+/).each do |line|
      case line
      when /<user /i
        @restrict_users = /<user (.*)>/i.match(line)[1].scan(/\d+/).collect { |i| i.to_i}
      when /<minus (\d+)>/i
        @restrict_minus = (100 - $1.to_i)/100.0
      end
    end
  end
 
  def user_params(actor_id, param_id)
    if @restrict_users.empty? || @restrict_users.include?(actor_id)
      value = params[param_id]
    else
      value = (params[param_id] * @restrict_minus).to_i
    end
    value
  end
 
  attr_accessor :restrict_users
  attr_accessor :restrict_minus
end
 
class Game_Actor < Game_Battler
  def param_plus(param_id)
    equips.compact.inject(super) {|r, item| r += item.user_params(@actor_id, param_id) }
  end
end
Apologies if i misunderstood, but basically you're trying to find a way to copy the effect of this code in javascript? If so I'll try to help, apologies if im off, but I'll try my best.


for the first line of code, this is the best i could think of.


#RUBY
$data_weapons.compact.each { |w| w.build_equipment_restrictions }

#=================================================================
#================================================================

//JAVASCRIPT
$dataWeapons.forEach( function( w ) {
//check if the weapon exists.
if ( w )
//executewhatever code you want here, below is an example.
w.buildEquipRestrictions();
};







for the 3rd line of code.
 


#RUBY
@restrict_users.empty? || @restrict_users.include?(actor_id)

//JAVASCRIPT
restrictUsers.length == 0 || restrictUsers.indexOf( actorId ) >= 0;



if this is what you're looking for i can look into the other lines as well( my ruby is a bit rusty and i cant think of solutions off the top of my head for them ), just let me know, if not sorry xD I probably misunderstood, apologies.
That last line would be restrictUsers.length === 0, not > 0, since it's checking if the array is empty.
Haha, Thanks shaz, glad you caught that, sorry I'm a bit tired atm ^^;

Original thread: https://forums.rpgmakerweb.com/threads/whats-the-equivalent-of-those-ruby-line-in-js.71742/