Ruby/RGSSx questions that don't deserve their own thread

I don't get the whole picture of what you're trying to do, but if you want to make a notetag and read it
Code:
class RPG::BaseItem
  def atk_scale
    @atk_scale ||= lambda do 
      note[/<scaling\s*:\s*(.+),(.+)>/i] ? [$1.to_s, $2.to_s] : ['A', 'A']
    end.call
  end
end
The notetag is <scaling: A,B>, and if you call it as $data_weapons[1].atk_scale it should return ['A', 'B']
@TheoAllen
Is there any reason for using lambda there?
I'm just curious why did you use it, seems like a needless thing to me, unless I'm missing something.
@Sixth it is unnecessary, I just find it ... stylish. Rather than going ...
Code:
class RPG::BaseItem
  def atk_scale
   return @atk_scale if @atk_scale
   ... write the rest of code to define @atk_scale here ...
   return @atk_scale
  end
end
I read it as .... this variable, if not defined yet, read this "code block" but I don't want it as a separate function.
Hey - for some reason, I can't get Sprite_Battler to reference it's Battler.
I've been using it to run a timer for the Battler, but it keeps treating the Battler as a nil class.
Spoiler
Code:
##------------------------------------------------------------------------------
#**Game Battler Class
##------------------------------------------------------------------------------
class Game_Battler < Game_BattlerBase
  attr_accessor :idle_timer
  alias in_idle_timer initialize
  def initialize
  in_idle_timer
   @idle_timer = 0
  end
end
##------------------------------------------------------------------------------
#**Sprite Battler Class
##------------------------------------------------------------------------------
class Sprite_Battler < Sprite_Base
  #-----------------------------------------------------------------------------
  #*Update Idle Frame Timer
  #-----------------------------------------------------------------------------
  alias up_sprite_timer update
  def update
  up_sprite_timer
   up_idle_timer
  end
  #-----------------------------------------------------------------------------
  #*Idle Frame Timer
  #-----------------------------------------------------------------------------
  def up_idle_timer
    @battler.idle_timer += 1
    @battler.idle_timer = 0 if @battler.idle_timer > 100
  end
 
end
For whatever reason, I always get a class nil error.
It's because when actor battlers are created, it doesn't have @battler
Code:
  def create_actors
    @actor_sprites = Array.new(4) { Sprite_Battler.new(@viewport1) }
  end
The fix would be simply
Code:
  def up_idle_timer
   return unless @battler
   @battler.idle_timer += 1
   @battler.idle_timer = 0 if @battler.idle_timer > 100
  end
Thanks, I did find a similar fix with using "if @battler" but whenever it comes to getting their idle types from their notes. The aliens show up to take everyone home.
hrKzbEJ.gif

It's actually pretty frustrating, that it went together pretty easy during the first build.

edit:
Okay, now things are working, I had used "=" instead of "==" for the Idle_Index. So I hope it not a jinx but I think it's good now, thanks!
Hi there,
I want to ask how to run 'Wait' script within Moveroute of Character?
SceneManager.scene.wait(x) seem doesn't work - _ -
Pls Help T.T
(ah wait, i posted in wrong section : O pls move it to right one for me, thks)
Moderator note: Merging this with Ruby/RGSSx questions that don't deserve their own thread.
Trying to get the player to use a "bike item" - basically you use a key item, and you switch a faster moving mode.

Only problem I'm having is to get the same item trigger the ON/OFF toggle, since it just runs both at the same time.
Code:
def bike_item_use
 
   $game_player.get_on_bike  if $game_player.on_bike == false
   $game_player.get_off_bike if $game_player.on_bike == true

end

I need something that can break this up - so they don't just run back to back when you use the key item.
Trying to get the player to use a "bike item" - basically you use a key item, and you switch a faster moving mode.

Only problem I'm having is to get the same item trigger the ON/OFF toggle, since it just runs both at the same time.
Code:
def bike_item_use
 
   $game_player.get_on_bike  if $game_player.on_bike == false
   $game_player.get_off_bike if $game_player.on_bike == true

end

I need something that can break this up - so they don't just run back to back when you use the key item.

very simple = |
Code:
def bike_item_use
   if $game_player.get_on_bike
      $game_player.on_bike == false
   else
      $game_player.on_bike == true
end
end
That worked perfectly - thanks!
Guess this is a double post - Trying to make a simple "Enemy Scan" script, but for some reason the message is displayed twice?
Spoiler
Code:
class Game_Enemy < Game_Battler
 
  attr_accessor :scan_info
 
  alias in_scan_info initialize
  def initialize(index, enemy_id)
  in_scan_info(index, enemy_id)
  
  if enemy.note =~ /<info:(.*)>/
   @scan_info = "#$1".to_s
  else
   @scan_info = "It's just - NOTHING!"
  end
 
  end
 
 
end

def scan_enemy(b)
 
  $game_message.add(b.scan_info)
  BattleManager.wait_for_text
 
end

I checked the skill to see if it was hitting twice, but it's not. Kind of clueless why its doing this.
You can check if the method itself is called twice in the same frame if you just put this debug line at the start of that scan_enemy method:
Code:
p "scan_enemy method run at #{Graphics.frame_count}!"

Using a damage/hit prediction script is a common reason of running all damage formula calculations twice.
If you use such a script, that might be why your message is shown twice.
These scripts often forget that the damage formula can be used for many other things and not just for simple damage number calculations.
I think it's got to be checking things twice. But it's weird, since I did have another script earlier that didn't have this issue. Though maybe it had to do with the load order?

But if I do route things to a common event, it reads once. Which is workable, but really what I was going for at keeping it simple.
Is there a way to make the window background transparent inside battles? Apparently it's not possible to do it the standard way. Is there a snippet I can potentially use to make it's opacity to 0 or just quickly replace the window image?
Using regular VX, btw.
@ShinNessTen you may get a better answer if you ask this as a request in rgss2 script forum. This particular topic is for Ruby learning, not for asking a snippet.
Recently I came across a post that explained how to use choices in a script (adding more than 4 chices) and it explained (I believe by Shaz) how to add the If statements that calls the functions for each choice, but I cannot find it. Does anyone know of it or can explain how to do the calls after choices are made in a script?
I'm using one of Yanflys old (VX, not ace) scripts that lets me buy common events. In that script, I can set a limit to how many times I can buy one common event.
But it seems you cannot reset the number of times you have bought a common event, once you buy one. I want to know if there is a potential script call I can use to increase the number of times I can buy a common event again.
Here's the script in question:
@ShinNessTen as I said in other day, you better of creating a support thread instead of asking here.
RGSS3 / For Window_Message:
I'm trying to adjust a message box's height according to it's $game_message.texts.size value from the start of a conversation.
I can adjust it fine when it's a second/third/etc message box by adding self.height = x in def new_page.

But right now, there's a tiny split second of time on the first message where it jitters from the default height to the adjusted height.
How could I try to set the height smoothly from the start?

insta.gif

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/