Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

new window

Urborg

Member

hi there
is there a way to show a new valor in a window on the menu?

i mean i created a new window in the menu (replaced the steps window,as some tutorial makes you do)
than i would like to create a new character variable (don't know if is the right term) such as gold owned hp or mp that would be displayed in that window

like say... moral or sanity or honour when that variable riches 0 or his maximum valor something happens

like when moral is 0 the character runs away and gameover .. or.. something
i'm pretty much sure that is possible

could someone tell me how?

thanks
 

Urborg

Member

i did it someway

i made  a class called Sanity like that

class Sanity
  attr_accessor :sanity
  $sanity = 100

  def initialize (n)
  $sanity -= n
  end
end

than i put in the window i created before, where i wanted to be displayed the valor
blablabla..
self.contents.draw_text (4, 32, 120, 32, $sanity.to_s, 2)
blablablaend
than i call it via event with this comand Sanity.new(10) if i want the char to loose 10 san and so on

it works but i can imagine is not the best way to do  it
maby it needs too many operations don't know
if someone knows a better way..

and now i'm looking for a way to make something happen if san reaches 0
 
Well, theres nothing WRONG with the way you did it, but it's not exactly how most people would go about it. I could make a better script of what you did, but I'm far too lazy. :D

But, to make something happen, there are multiple things you could do!

You could make events where if you have very low sanity, people will fear you, or maybe the men in white coats will chase after you. And if you have high sanity... uh... then, you could bask in the knowledge that you aren't crazy?
 

khmp

Sponsor

I wouldn't use a global and have a class manipulate the global by the instantiation of a new Sanity class. I would make an instance scope variable and place it into a module. This way you are manipulating sanity safely and without the use of the globals. I would use a module because there isn't really any need for an initialize as we are only dealing with one variable. Plus the added bonus of module's is no initialize no need to have in script calls:
Code:
temp = Sanity.new 
temp.manipulate_sanity

Quick example:

Code:
module Sanity
  # Default initialization of our sanity class variable.
  @sanity = 100
  # The maximum amount of sanity.
  MAX_SANITY = 100
  # The minimum amount of sanity.
  MIN_SANITY = 0

  # Lost sanity.
  def self.lose_sanity(n)
    return if n < 0
    @sanity = [@sanity - n, MIN_SANITY].max
  end

  # Gain sanity
  def self.gain_sanity(n)
    return if n < 0
    @sanity = [@sanity + n, MAX_SANITY].min
  end
  
  # Access sanity
  def self.sanity
    return @sanity
  end
end

# Test code below.
Sanity.gain_sanity(5)
Sanity.lose_sanity(50)
Sanity.gain_sanity(34)
p Sanity.sanity # 84
Sanity.gain_sanity(98034)
p Sanity.sanity # 100
Sanity.gain_sanity(-98034)
p Sanity.sanity # 100

Good luck with it Urborg! :thumb:
 

Urborg

Member

but how can i link an event to a script?
i mean
i have this sanity valor ,now if i want an event in the game to do something if the sanity is 0 i am forced to do it with a script?
or i can use event commands?

cause i'm not very good at moving an event and make him talk with scripting
 

khmp

Sponsor

You could create a Conditional Branch which has a Script option. Just do a test to see if sanity is at zero. This would be a parallel process event.

The event commands:
Conditional Branch: Script: Sanity.sanity == 0
  # Here is where you would have the work that means no sanity.
Branch End
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top