The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: .:Pyroken Serafoculus:. on March 06, 2007, 11:11:45 AM

Title: I'm clueless...
Post by: .:Pyroken Serafoculus:. on March 06, 2007, 11:11:45 AM
This might sound extremely stupid, but I have two problems with some minor scripts of mine. First of all, everytime I try to change a global variable using the script event command, nothing happens. Say, if I want to disable a type of CMS, I make a method and enclose it in an if statement asking whether an already defined boolean (CMS_ENABLED?) is true. Now, the script is fine, that I know, but when I use a script from an event in the game saying

CMS_ENABLED? = false

the switch doesn't change, apparently, because the CBS is still enabled. Note that this is a rhetorical situation, I have no idea why anyone would want to disable the entire CMS.

Secondly, what's the problem with this code? I placed it above Main, it makes some changes with the message class. Every time I run it, it keeps interpreting * or + as an undefined method. Am I doing anything right at all?

#----------------------------------------------------------------------------
# Message Adjustment
#----------------------------------------------------------------------------
# Making the message window dynamically adjustable according to the text
#----------------------------------------------------------------------------

class Window_Message < Window_Selectable
  def initialize
    @mes_width = (@row_max * 32) + 50
    @mes_height = (@column_max * 32) + 50
    @mes_x = 80 - mes_width / 2
    @mes_y = 304 - mes_height / 2
    super(@mes_x, @mes_y, @mes_width, @mes_height)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.visible = false
    self.z = 9998
    @fade_in = false
    @fade_out = false
    @contents_showing = false
    @cursor_width = 0
    self.active = false
    self.index = -1
  end
end
Title: Re: I'm clueless...
Post by: Shinami on March 06, 2007, 11:35:09 AM
Why are on earth are you putting a local variable in your call script command? Just kidding! What you just posted is called a local variable.
CMS_ENABLED? = false
It is contained and used only within the method it is declared in. If you declared "foobar = 0" in method "initialize", you could use "foobar" in the method you declared it in but if you were to try and use "foobar" in the method "main", it would flag it as an error unless you were to declare another local variable called "foobar"


@CMS_ENABLED? = false
This piece is called an instance variable. They are usable throughout the entire class so be careful when using these to check true/false or what not.

$CMS_ENABLED? = false
THIS is a global variable. As the name global would suggest, these are usable and callable throughout ANY script you have. I've only used these once and that was in a small item window script I made for personal use.

If you feel insulted by my explanations, I apologize for I only wanted to clear up any misunderstandings you may have had over the types of variables.

On your message script, it seems to be flagging @row_max as an containing nil. What is the exact purpose of your Message_Window script?
Title: Re: I'm clueless...
Post by: Blizzard on March 06, 2007, 12:10:56 PM
Heh, it's not local, it's a constant. Constants start with a capital letter and can't be changed during the execution.
Title: Re: I'm clueless...
Post by: Shinami on March 06, 2007, 12:27:23 PM
 :-[ oooh... *crawls off into a corner*  ;9
Title: Re: I'm clueless...
Post by: Blizzard on March 06, 2007, 12:38:50 PM
And basically the ? at the end doesn't work with variables. =/
Title: Re: I'm clueless...
Post by: Shinami on March 06, 2007, 12:46:33 PM
*speaks from corner* That's true. I found that out when messing around with Input method check thingies. All the ? does is work as a check if a thing is true or false or so I believe.
Title: Re: I'm clueless...
Post by: Blizzard on March 06, 2007, 12:58:06 PM
It works for methods, i.e. "def have_some_money?"
Title: Re: I'm clueless...
Post by: Shinami on March 06, 2007, 01:07:30 PM
Hmmm...strange. Regardless, any idea what's causing Pyroken's Window_Message modification to toss an error? I really hate quoting myself but...I'm clueless like Pyroken as to why it's throwing an error when @row_max IS defined in Window_Selectable. Perhaps the method was simply misused?
QuoteOn your message script, it seems to be flagging @row_max as an containing nil. What is the exact purpose of your Message_Window script?/
Title: Re: I'm clueless...
Post by: Blizzard on March 06, 2007, 01:23:11 PM
There is no @row_max in Window_Selectable. row_max is a method. Use self.row_max instead.
Title: Re: I'm clueless...
Post by: .:Pyroken Serafoculus:. on March 06, 2007, 01:40:35 PM
QuoteIt is contained and used only within the method it is declared in. If you declared "foobar = 0" in method "initialize", you could use "foobar" in the method you declared it in but if you were to try and use "foobar" in the method "main", it would flag it as an error unless you were to declare another local variable called "foobar"

Really? I thought variables with nothing before them were global variables. I'll try that...

Actually, I wasn't using a variable for that, I wanted a boolean, like a switch in eventing. But I see what you mean.

Quote1) On your message script, it seems to be flagging @row_max as an containing nil. 2) What is the exact purpose of your Message_Window script?

1) I had no idea it was doing that, either. o.O

2) This script is supposed to adjust the dimensions of the message window depending on the contents. Like if there's only word in the box, it would resize the message box to fit in only that word with no excess space.

QuoteThere is no @row_max in Window_Selectable. row_max is a method. Use self.row_max instead.

I tried that, but now it starts thinking the "+" in Line 44 of Window_Selectable (row_max, essentially) is a method. Weird.
Title: Re: I'm clueless...
Post by: Blizzard on March 06, 2007, 02:04:03 PM
I'd say use all like in a usualy window, then just add self.width = self.contents.width + 32 and self.height = self.contents.height + 32
Title: Re: I'm clueless...
Post by: .:Pyroken Serafoculus:. on March 06, 2007, 05:10:37 PM
But self.contents.width and height aren't synonimous with row_max and column_max. They're only the dimensions of the contents which are modeled off the dimensions of the window, which aren't dynamic. I tried it out; that's how I figured it out.

Man!