Hello,
I am using RMXP and I try to make a script for a friend of mine.
However, I got a problem with it showing and changing text.
I got this code:
class Window_Desc < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(178, 74, 362, 302)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(120, 0, 300, 32, $j[1].to_s )
self.contents.font.color = normal_color
self.contents.draw_text(0, 64, 320, 32, "Description: " + $d1[1])
self.contents.draw_text(0, 96, 320, 32, $d2[1].to_s())
self.contents.draw_text(0, 128, 300, 32, "Condition: "+$cc[1])
self.contents.draw_text(0, 160, 300, 32, "Reward: "$r[1])
$stat = $game_variables[0001].to_s()
case $game_variables[0001]
when 0
self.contents.font.color = normal_color
$stat = " Available"
when 1
self.contents.font.color = Color.new(255,255,0)
$stat = " In-Progress"
else
self.contents.font.color = Color.new(0,255,0)
$stat = " Complete"
end
self.contents.draw_text(0, 192, 300, 32, "Status:"+$stat)
end
end
and now all the "$" I can't change to the second variable on the list.
Now I have it show the second variable with the $j[1] and such.
I wonder if anyone know what to do to make sure it does works.
~Tigurus
It would help to know exactly what all those unneeded global variables actually equaled.
Alright, well, I can show the arrays if needed and the event it summons. let me see.
Array:
class Game_Quest
def initialize
# Create actor array
@j = []
@d1 = []
@d2 = []
@cc = []
@r = []
@s = []
end
end
Event which summons the windows.
Note that in the same event a second can be made by changing the "0" to "1" and so on.
$missionboardname="Iron Wolf Board"
$j[0]="Bass Fishing"
$d1[0]="The camp leader wants fish"
$d2[0]="He wants Bass"
$cc[0]="Fish 10 Bass fishes"
$r[0]="Your dinner"
$s[0]=$stat
$scene = Scene_Jobs.new
I hope this is what is needed. Sorry for the convenience.
Not to insult you at all, but that code is absolutely horrible.
Game_Quest = Struct.new(:name, :j, :d1, :d2, :cc, :r, :s)
class Scene_Job
def initailize(*quests)
@quests = quests
@description_window = Window_Desc.new(@quests[0])
# etc, etc...
end
end
class Window_Desc < Window_Base
attr_reader :quest
def initialize(quest)
@quest = quest
# etc, etc...
end
def quest=(quest)
@quest = quest
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(120, 0, 300, 32, @quest.j )
self.contents.font.color = normal_color
self.contents.draw_text(0, 64, 320, 32, "Description: " + @quest.d1)
self.contents.draw_text(0, 96, 320, 32, @quest.d2)
self.contents.draw_text(0, 128, 300, 32, "Condition: " + @quest.cc)
self.contents.draw_text(0, 160, 300, 32, "Reward: " + @quest.r)
# This line is unneeded, it is simply setting it to itself, since the script call sets it this value to $stat, whatever that may be...
# $stat = $game_variables[0001].to_s()
case $game_variables[1]
when 0
self.contents.font.color = normal_color
@quest.s = " Available"
when 1
self.contents.font.color = Color.new(255,255,0)
@quest.s = " In-Progress"
else
self.contents.font.color = Color.new(0,255,0)
@quest.s = " Complete"
end
self.contents.draw_text(0, 192, 300, 32, "Status:" + @quest.s )
end
end
Some things to remember are to not use global variables like that, and to not use ".to_s" on strings, they are strings already.
What I got there should be a pointer in the right direction. I didn't check any of it and it is incomplete, I just typed it into the message box here, so its possible I missed an "end" or something. In your scene, whenever use use a snippet like "@description_window.quest = @quests[index]" it will automatically refresh it to show the next selected quest.
EDIT:
For the script call, create quests one of two ways:
q = Game_Quest.new(<ARGUMENTS IN ORDER THEY ARE IN ABOVE>)
or
q = Game_Quest.new
q.name = ""
q.j = ""
# etc, etc...
I don't feel insulted really. I am very new to scripting and to tell you the truth, someone else made the beginning (which are the arrays and windows) I just continued from there.
However, as I got more windows so I am pretty unsure if the rest of the script is good.
I will use this now though. Though, would you mind if you could look at the rest of the script I got? :/
Furthermore, if I need any help of your part of the script, I will ask in this topic and I bet I will need more help :(
(I am so bad :()
Yeah, I can look at it.
I would also suggest that you take a look at a few existing quest scripts out there to see how they are done. They are all a bit different, but you may pick up an idea or two.
i never knew there was a Struct class in ruby that u can use to make dummy classes
Thanks, I will post everything I had here then :)
For most I did myself I looked at the existing scripts. I mostly looked at Window_Menustatus. That was a great help I'd say.
Anyhow, here's all snippits of the script I was busy with. (I know it will be horrible in your superior scripter brain)
I also show a screenshot of how I wanted it to look.
$j=[]
$d1=[]
$d2=[]
$cc=[]
$r=[]
$s=[]
#==============================================================================
# ** Game_Quest
#------------------------------------------------------------------------------
# This class handles the quests.
#==============================================================================
class Game_Quest
def initialize
# Create actor array
@j = []
@d1 = []
@d2 = []
@cc = []
@r = []
@s = []
end
end
#==============================================================================
# ** Window_List_Title
#------------------------------------------------------------------------------
# This window displays the Title of the board
#==============================================================================
class Window_List_Title < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(30, 10, 148, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(37, 0, 76, 32, "Jobs")
end
end
#==============================================================================
# ** Window_List
#------------------------------------------------------------------------------
# This window displays the jobs on the board.
#==============================================================================
class Window_List < Window_Selectable
def initialize
super(30, 74, 148, 302)
self.contents = Bitmap.new(width - 32, height - 32 * 32)
refresh
self.active = active
self.index = 1
end
def refresh
self.contents.clear
@item_max = $j.size
for i in 0...$j.size
x = 64
y = i * 32
self.contents.draw_text(5, y, 148, 32, $j[i])
end
end
#-------------------------------------------------------------------------------
# Cursor Update
#-------------------------------------------------------------------------------
def update_cursor_rect
super
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(0, @index * 32, self.width - 32, 32)
end
if @index >= 0
self.oy = 0
self.cursor_rect.set(0, @index * 32, self.width - 32, 32)
end
if @index >= 8
self.oy = 256
self.cursor_rect.set(0, (@index - 8) * 32, self.width - 32, 32)
end
end
end
class Scene_Jobs
def main
@window1 = Window_Header.new
@window2 = Window_List.new
@window3 = Window_Desc.new
@window4 = Window_List_Title.new
# Perform a transition
Graphics.transition
# Loop forever
loop do
# Update graphics
Graphics.update
# Update input
Input.update
# Call the update method
update
if $scene != self
# Exit the loop
break
end
end
Graphics.freeze
@window1.dispose
@window2.dispose
@window3.dispose
@window4.dispose
end
# The update method.
# Checks if cancel is pressed and exits this scene
def update
@window1.update
@window2.update
@window3.update
@window4.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
end
end
The other window is the one I've sent a in the other post.
(http://astraeastrial.webs.com/Board.png)
Your primary issue is the liberal use of global variables. A system like this would maybe use 1, if that. An array instance variable in Game_System or Game_Party called @quests would more than suffice. Simply add instances of a Game_Quests to it, and access it through your scene. It will also automatically save with the game data, without having to modify the save/load methods.
class Game_Party
attr_accessor :quests
alias zer0_quests_init initialize
def initialize
@quests = []
zer0_quests_init
end
end
From here you can access all of your current quests with a simple reference to $game_party.quests.
You can add some methods for adding/removing quests from the array in a simpler way if desired, or just access it directly.
The actual quest class should be relatively simple, mainly just an single object to keep your data structured, like the simple Struct I posted above, though maybe not quite that basic. (Just in case you don't know, a Struct is basically the same as a class without methods)
I'm not sure exactly what your problem is. Is it accessing the data, or drawing it as desired on the window?
Alright, thank you. :)
I will see what I can do with it.
My problem is no more as it had to do with the codes that you revamped a bit. Now I need to make it 100% suitable and hope it will work like a charm :)
So, when I get into more questions, I will let you know :)
Sounds good, glad I could help. ;)
Sorry to bother you again Zero.
But I can't get it to show a window.
Personally, I also don't know how to continue with the script you made, as I am still kind of a newbie in scripting.
I can't seem to summon the script and windows :(