Chaos Project

RPG Maker => General Discussion => Troubleshooting / Help => Topic started by: LeviAlvi on September 12, 2013, 02:22:26 pm

Title: Help in viewing a variable to my menu
Post by: LeviAlvi on September 12, 2013, 02:22:26 pm
I want to view a variable in my menu. I have this script but I don't know if I'm doing right.

Code
Spoiler: ShowHide
#==============================================================================
# ** Window_Points2
#------------------------------------------------------------------------------
#  This window displays amount of your points.
#==============================================================================

class Window_Points2 < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 300, 300)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   pts = "Points"
   n = 1
   extra = $game_variables[49]
   self.contents.font.color = system_color
   self.contents.draw_text(0, 12, 120, 32, pts)
   self.contents.font.color = normal_color
  self.contents.draw_text(0+46, 12, 120, 32, extra, 2)
 end
end



I have an error in this code: self.contents.draw_text(0+46, 12, 120, 32, extra, 2)

thanks
Title: Re: Help in viewing a variable to my menu
Post by: KK20 on September 12, 2013, 04:36:09 pm
Gotta put a to_s to turn a number into a string.
extra = $game_variables[49].to_s
Title: Re: Help in viewing a variable to my menu
Post by: PhoenixFire on September 12, 2013, 04:39:45 pm
I have something really similar in my game, but it displays if certain switches are on or off. So I'm not sure if events would even help you or not. I do like the thought behind this though, as I use a similar system, though not just 'points'. I have a good/evil system I'm incorporating, and it would be nice to be able to let the player know how good or not they are..


EDIT: I assume that extra = $game_variables[49] means that you're using variable number 49 as what you're importing data from into your script?
Title: Re: Help in viewing a variable to my menu
Post by: LeviAlvi on September 12, 2013, 04:48:42 pm
You're a life save KK20! I'm doing this for hours but nothing happens.

BTW, can you call a menu using a script call? I want to view this point system only when the puzzles are on. and I'll close the menu again when the puzzle is finished
Title: Re: Help in viewing a variable to my menu
Post by: KK20 on September 12, 2013, 05:11:40 pm
If the puzzle isn't already handled by a scene, I think what you want to do is make a global variable handle everything via script calls. When you want the window to show up, do
$pts2_window = Window_Points2.new

In a parallel process, do
unless $pts2_window.nil?
  $pts2_window.update
end

And when you want to get rid of the window
$pts2_window.dispose
$pts2_window = nil

It's not the best way to handle things, but I also don't know how you want things to look.
Title: Re: Help in viewing a variable to my menu
Post by: LeviAlvi on September 12, 2013, 05:20:04 pm
can you make a full sample with that script please?

here's the picture, it's just edited though   :^_^':

(http://img7.imageshack.us/img7/3571/luij.png)

on the upper right, it's the timer, and beside the timer, thats the window that I wanted to show when the puzzle is on
Title: Re: Help in viewing a variable to my menu
Post by: LeviAlvi on September 13, 2013, 08:15:43 am
Forget the script for the above, I just wanted to know how to call timer in script? and how to dispose it. I copied the script in sprite_timer and it can view my variable.

I can't move if I will use the script above that's why I will use the method in timer. Thanks :)
Title: Re: Help in viewing a variable to my menu
Post by: KK20 on September 13, 2013, 06:34:02 pm
Because it still looks like you're on Scene Map, you can just do
$game_system.timer_working = true

to display the timer and
$game_system.timer_working = 
false

to remove it.
To set it, use
$game_system.timer = SECONDS
Title: Re: Help in viewing a variable to my menu
Post by: LeviAlvi on September 13, 2013, 10:29:22 pm
I copied the script in sprite_timer and I will use that to view my variables. but I got a NoMethodError

#==============================================================================
# ** Sprite_Timer
#------------------------------------------------------------------------------
#  This sprite is used to display the timer.It observes the $game_system
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Timer2 < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super
    self.bitmap = Bitmap.new(88, 108)
    self.bitmap.font.name = "Arial"
    self.bitmap.font.size = 32
    self.x = 640 - self.bitmap.width
    self.y = 0
    self.z = 500
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Set timer to visible if working
    self.visible = $game_system.timer_working2
    # If timer needs to be redrawn
    if $game_system.timer / Graphics.frame_rate != @total_sec
      # Clear window contents
      self.bitmap.clear
      # Calculate total number of seconds
      @total_sec = $game_system.timer / Graphics.frame_rate
      # Make a string for displaying the timer
      min = @total_sec / 60
      sec = @total_sec % 60
      text = sprintf($game_variables[50].to_s)
      # Draw timer
      self.bitmap.font.color.set(0,0,0)
      self.bitmap.draw_text(self.bitmap.rect, text, 1)
    end
  end
end


I used this script: $game_system.timer_working2     to view it. What's wrong with this?
Title: Re: Help in viewing a variable to my menu
Post by: ShadowPierce on September 14, 2013, 03:08:13 pm
Don't forget to say thanks and level up people who help you... ;)
Title: Re: Help in viewing a variable to my menu
Post by: KK20 on September 14, 2013, 03:50:27 pm
Is there any reason why you have to make another timer class that does the exact same thing? Why can't you use the default one? In order to make a second one, you will need to add more variables to some of the pre-existing scripts to get this to work. What you have right now wouldn't even function properly, if at all.

NoMethodError means exactly what it says: the method you are trying to use has not been defined anywhere within your scripts. You can't just slap on a '2' at the end of timer_working and expect it to do something. Computers are fast, not smart.

You will need to make an attr_accessor in Game_System called timer_working2 first.
class Game_System
  attr_accessor: timer_working2
  alias init_2nd_timer initialize
  def initialize
    @timer_working2 = false
    init_2nd_timer
  end
end

But after doing that, you will need to create the Sprite_Timer instance in Spriteset_Map, etc. In other words, too much trouble for its worth.
Title: Re: Help in viewing a variable to my menu
Post by: LeviAlvi on September 14, 2013, 10:03:08 pm
I can't level up you now. I'll level you up later KK20.  :naughty:

thanks for the trouble though. I'll just remove the timer and make it to view my points.