Help in viewing a variable to my menu

Started by LeviAlvi, September 12, 2013, 02:22:26 pm

Previous topic - Next topic

LeviAlvi

September 12, 2013, 02:22:26 pm Last Edit: September 12, 2013, 04:36:26 pm by KK20
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
Spoiler: ShowHide
hahahahaha

KK20

Gotta put a to_s to turn a number into a string.
extra = $game_variables[49].to_s

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

PhoenixFire

September 12, 2013, 04:39:45 pm #2 Last Edit: September 12, 2013, 04:41:20 pm by DigitalSoul
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?
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

LeviAlvi

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
Spoiler: ShowHide
hahahahaha

KK20

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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

LeviAlvi

can you make a full sample with that script please?

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



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
Spoiler: ShowHide
hahahahaha

LeviAlvi

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 :)
Spoiler: ShowHide
hahahahaha

KK20

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

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

LeviAlvi

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?
Spoiler: ShowHide
hahahahaha

ShadowPierce

Don't forget to say thanks and level up people who help you... ;)

Spoiler: ShowHide
Quote from: Blizzard on February 16, 2011, 03:44:48 pmThere you go. It's the proof that SDK is crap. It's incompatible with itself.
3DS Friend Code: ShowHide
1161-0627-9890

KK20

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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

LeviAlvi

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.
Spoiler: ShowHide
hahahahaha