Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Changing Module inside Eventing, I'm just wondering :P
Jonnie19
post Nov 20 2012, 02:04 PM
Post #1


Are you trying to rise from your lullaby?
Group Icon

Group: Director
Posts: 1,321
Type: Developer
RM Skill: Intermediate
Rev Points: 45




So, I'm now jumping into scripting, so after working with abit of JS thanks to Code Acadamy. I'm attempting to make my first menu script...
Basically I am looking for three seperate menu backgrounds for each of the three Characters. I'm using GubID's FFT Menu Script Tutorial to help start me out smile.gif

Anywho, here is the beginning of the script (At the moment I'm just trying to get the actual thing to change when I use an Script Even command.

My small script
CODE
module Lullaby_Menu
  #-----------------------------------------------------------------------------
  # Menu_Background_Type
  #-----------------------------------------------------------------------------
  # 0 = First Character
  # 1 = Second Character
  # 2 = Third Character
  #-----------------------------------------------------------------------------
  Menu_Character_Type = 0
  First_Chara_BG = "Menu_Back"
  Second_Chara_BG = "Menu_Back1"
  Third_Chara_BG = "Menu_Back2"
end
class Scene_Menu < Scene_Base
  def start
    create_menu_background
    case Lullaby_Menu::Menu_Character_Type
    when 0
      bitmap = Cache.system(Lullaby_Menu::First_Chara_BG)
      @menuback_sprite.bitmap = bitmap
    when 1
      bitmap = Cache.system(Lullaby_Menu::Second_Chara_BG)
      @menuback_sprite.bitmap = bitmap
    when 2
      bitmap = Cache.system(Lullaby_Menu::Third_Chara_BG)
      @menuback_sprite.bitmap = bitmap
    end
  end
  def update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    end
  end
  def terminate
    super
    dispose_menu_background
  end
end

Now, what I wanna know is how to change
CODE
Menu_Character_Type = 0

inside an event command.
I know this is probably easy for experience scripters, and may seem a stupid question, but hey I'm learning.

Thanks for your help in advance tongue.gif


__________________________

Finished Projects:
Slenderman's Army:


Go to the top of the page
 
+Quote Post
   
Thallion
post Nov 20 2012, 07:38 PM
Post #2


Level 5
Group Icon

Group: Member
Posts: 68
Type: Scripter
RM Skill: Skilled
Rev Points: 10




That variable is a constant b/c it starts with a capital letter. You can't change the value of a constant at runtime.
Go to the top of the page
 
+Quote Post
   
Jonnie19
post Nov 26 2012, 03:33 PM
Post #3


Are you trying to rise from your lullaby?
Group Icon

Group: Director
Posts: 1,321
Type: Developer
RM Skill: Intermediate
Rev Points: 45




Okay, thanks to Jens and Thallion for both helping me correct the problem...now I have a syntax error, which I am trying to solve, now perhaps an experienced scripter could help solve the issue smile.gif
CODE
module Lullaby_Menu
  def initialize
    First_Chara_BG = "Menu_Back",
    Second_Chara_BG = "Menu_Back1",
    Third_Chara_BG = "Menu_Back2",
    end
  def Lullaby_Menu.menu_character_type
        if @menu_character_type.nil?
          @menu_character_type = 0
        end
      end
       return @menu_character_type
     end
      def Lullaby_Menu.menu_character_type=(value)
       @menu_character_type = (value)
     end
   end
end

There is something wrong with the Syntax of this module....(thank you Jens tongue.gif) It's probably something simple but i've tried going through the coding and I'm not sure I've got this right smile.gif
Help really appreciated tongue.gif


__________________________

Finished Projects:
Slenderman's Army:


Go to the top of the page
 
+Quote Post
   
Philip
post Nov 26 2012, 06:24 PM
Post #4


Nura (The Jade Ring)
Group Icon

Group: Revolutionary
Posts: 327
Type: Developer
RM Skill: Masterful




QUOTE (Jonnie19 @ Nov 26 2012, 05:33 PM) *
Okay, thanks to Jens and Thallion for both helping me correct the problem...now I have a syntax error, which I am trying to solve, now perhaps an experienced scripter could help solve the issue smile.gif
CODE
module Lullaby_Menu
  def initialize
    First_Chara_BG = "Menu_Back",
    Second_Chara_BG = "Menu_Back1",
    Third_Chara_BG = "Menu_Back2",
    end
  def Lullaby_Menu.menu_character_type
        if @menu_character_type.nil?
          @menu_character_type = 0
        end
      end
       return @menu_character_type
     end
      def Lullaby_Menu.menu_character_type=(value)
       @menu_character_type = (value)
     end
   end
end

There is something wrong with the Syntax of this module....(thank you Jens tongue.gif) It's probably something simple but i've tried going through the coding and I'm not sure I've got this right smile.gif
Help really appreciated tongue.gif

You have too many end statements in your "Lullaby_Menu.menu_character_type" def


__________________________
"If your mind goes blank don't forget to turn off the sound." Unknown Author

Phil


Go to the top of the page
 
+Quote Post
   
Jonnie19
post Nov 27 2012, 08:02 AM
Post #5


Are you trying to rise from your lullaby?
Group Icon

Group: Director
Posts: 1,321
Type: Developer
RM Skill: Intermediate
Rev Points: 45




Still struggling with this one, i've removed said additional end that wasn't needed XD but i'm STILL I'm getting the error for Line 3...
I'm most likely being really stupid, I also noticed I wrote...mmodule :X
CODE
module Lullaby_Menu
  def initialize
    First_Chara_BG = "Menu_Back"
    Second_Chara_BG = "Menu_Back1"
    Third_Chara_BG = "Menu_Back2"
  end
  def Lullaby_Menu.menu_character_type
        if @menu_character_type.nil?
          @menu_character_type = 0
        end
       return @menu_character_type
     end
      def Lullaby_Menu.menu_character_type=(value)
       @menu_character_type = (value)
     end
   end
end


__________________________

Finished Projects:
Slenderman's Army:


Go to the top of the page
 
+Quote Post
   
Jens of Zanicuud
post Nov 27 2012, 08:13 AM
Post #6


Dark Jentleman
Group Icon

Group: Local Mod
Posts: 916
Type: Scripter
RM Skill: Skilled
Rev Points: 120




You can't declare constants inside a method (such as initialize); you must use @ variables if you want your module to "see" them outside the initialize method or just declare them as constants outside a method.
Try this one:

CODE
module Lullaby_Menu
  
  Chara_BGS = {
  1 => "Menu_Back",
  2 => "Menu_Back 2",
  3 => "Menu_Back 3",
  }
  
  def Lullaby_Menu.menu_character_type
      if @menu_character_type.nil?
          @menu_character_type = 0
        end
       return @menu_character_type
     end
    
  def Lullaby_Menu.menu_character_type=(value)
    @menu_character_type = (value)
  end
  
  def Lullaby_Menu.menu_picture
    return Chara_BGS[@menu_character_type]
  end
end


I've added a method (Lullaby_Menu.menu_picture) which gives you back the item in thehash named Chara_BGS, which matches with the @menu_character_type variable's value (e.g. if you want to call "Menu Back", just call Lullaby_Menu.menu_character_type= 1. If you want to access an element of the hash, just call Lullaby_Menu::Chara_BGS[index] where index is the number you see on the left of the hash - commonly named key).
Hashes are powerful instruments you should learn about, they solve a whole bunch of problems smile.gif

There should actually be another method to create that module using the initialize, but I have to read some documentation before saying that for sure.

For any issue concerning this point, just reply here or send me a PM smile.gif

I hope this can help,

Jens


__________________________
"Thorns are the rose's sweetest essence..."
-Jens of Zanicuud


Games I'm working on:
>

official website: TryAdIne eFfeCt

>

Games I worked on (mainly as a scripter):
>
(Warning: it's a 3rr3's project and it's in Italian!)


Awards

Go to the top of the page
 
+Quote Post
   
Philip
post Nov 27 2012, 12:38 PM
Post #7


Nura (The Jade Ring)
Group Icon

Group: Revolutionary
Posts: 327
Type: Developer
RM Skill: Masterful




QUOTE (Jens of Zanicuud @ Nov 27 2012, 10:13 AM) *
You can't declare constants inside a method (such as initialize); you must use @ variables if you want your module to "see" them outside the initialize method or just declare them as constants outside a method.
Try this one:

CODE
module Lullaby_Menu
  
  Chara_BGS = {
  1 => "Menu_Back",
  2 => "Menu_Back 2",
  3 => "Menu_Back 3",
  }
  
  def Lullaby_Menu.menu_character_type
      if @menu_character_type.nil?
          @menu_character_type = 0
        end
       return @menu_character_type
     end
    
  def Lullaby_Menu.menu_character_type=(value)
    @menu_character_type = (value)
  end
  
  def Lullaby_Menu.menu_picture
    return Chara_BGS[@menu_character_type]
  end
end


I've added a method (Lullaby_Menu.menu_picture) which gives you back the item in thehash named Chara_BGS, which matches with the @menu_character_type variable's value (e.g. if you want to call "Menu Back", just call Lullaby_Menu.menu_character_type= 1. If you want to access an element of the hash, just call Lullaby_Menu::Chara_BGS[index] where index is the number you see on the left of the hash - commonly named key).
Hashes are powerful instruments you should learn about, they solve a whole bunch of problems smile.gif

There should actually be another method to create that module using the initialize, but I have to read some documentation before saying that for sure.

For any issue concerning this point, just reply here or send me a PM smile.gif

I hope this can help,

Jens

Yeah I was thinking that but I've never tried it before so you got to it before me LOL.

@Jonnie not only can you not define constants inside a method you still had one too many ends in that module.



__________________________
"If your mind goes blank don't forget to turn off the sound." Unknown Author

Phil


Go to the top of the page
 
+Quote Post
   
Jens of Zanicuud
post Nov 28 2012, 12:56 PM
Post #8


Dark Jentleman
Group Icon

Group: Local Mod
Posts: 916
Type: Scripter
RM Skill: Skilled
Rev Points: 120




You're right, Philip smile.gif
I've taken care of that end in the snippet I posted in the previous reply, however.
That code I posted should (more or less) work...

Jens


__________________________
"Thorns are the rose's sweetest essence..."
-Jens of Zanicuud


Games I'm working on:
>

official website: TryAdIne eFfeCt

>

Games I worked on (mainly as a scripter):
>
(Warning: it's a 3rr3's project and it's in Italian!)


Awards

Go to the top of the page
 
+Quote Post
   
Jonnie19
post Nov 28 2012, 04:32 PM
Post #9


Are you trying to rise from your lullaby?
Group Icon

Group: Director
Posts: 1,321
Type: Developer
RM Skill: Intermediate
Rev Points: 45




Thankyou guys, it is now working perfectly, I never considered using Hash before now, but it really is alot easier XD so thanks to both of you for your help tongue.gif


__________________________

Finished Projects:
Slenderman's Army:


Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 18th June 2013 - 12:57 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker