Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Kiriashi

Random Number

Question

I am trying to open a scene if a random number = x, but no matter what, it opens the scene everytime.

 

@leonscookies = rand(10)
if @leonscookies = 6
   $scene = Scene_Gameover.new
end

It goes to the scene everytime.

 

I tried doing this:

@joy = rand(10)
print @joy

And it showed a random number just fine.

 

What am I doing wrong?

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Ah.. xD

 

Thanks guys. ^~^

 

 

EDIT: But printing a random number worked just fine. Just the scene thing didn't..

Share this post


Link to post
Share on other sites
  • 0

Check this out.

 

I have this code:

 

scriptlu.png

 

Which produces this:

 

resuly.png

 

I'm not using double equal signs.

Share this post


Link to post
Share on other sites
  • 0

if var = 4
 # Stuff
end

 

It first evaluates the conditional which sets var to 4 and returns 4

var = 4

 

It then comes to look like this:

if 4
 # Stuff
end

 

if (value) is anything other than nil or false it is considered as being true.

 

 

Note also that @number is a different variable from number so using == would probably give you an error.

Share this post


Link to post
Share on other sites
  • 0

It would have returned a nil I think if you were using == since 4 is not 5

 

That picture was actually an accidental paste. That's not the code I was using. xD

 

if var = 4
 # Stuff
end

 

It first evaluates the conditional which sets var to 4 and returns 4

var = 4

 

It then comes to look like this:

if 4
 # Stuff
end

 

if (value) is anything other than nil or false it is considered as being true.

 

 

Note also that @number is a different variable from number so using == would probably give you an error.

 

Thank you very much Zeriab! *hugs*

Share this post


Link to post
Share on other sites
  • 0

Oh, Zeriab, such a savior. And here I wanted to toy with Kiri! I never get to! -pouts-

Share this post


Link to post
Share on other sites
  • 0

^~^

 

 

weeeeeeeeeee.png

 

#===============================================================================
# * Zeriab and Leon are Awesome Window
#-------------------------------------------------------------------------------
# * Object Initialization
#===============================================================================
class Window_First < Window_Base
 def initialize
   super(180, 100, 256, 96)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
end
#===============================================================================
# * Refresh
#===============================================================================
def refresh
 self.contents.clear
 self.contents.font.color = text_color(2)
 self.contents.draw_text(0, 0, 256, 32, "ALL PRAISE ZERIAB!")
 self.contents.font.color = system_color
 self.contents.draw_text(85, 40, 256, 32, "...and Leon")
end

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...