- 189
- Posts
- 15
- Years
- Seen Jun 12, 2024
Hey all,
As you can probably guess from the topic title, I'm having a n00b problem with some coding. Now, I'm not uninitiated with coding, being a student of programming presently at university, but RGSS remains 99% unfamiliar to me. All I've worked with is Pascal and C.
As such, I figured that with the need to eventually script some major stuff for my game, it'd be best to start small, so I followed the suggestions of many more experienced coders and began work on modifying the Trainer Card script.
My aim was to implement a feature such that when one has the Trainer Card open, pressing the A button (i.e. the Z key) would show a separate screen for the badges, along with their titles (and maybe more, if I have room). Once there, one would simply press B (i.e. Esc or X) to return to the original screen.
So I made a duplicate of the pbStartScene and pbDrawTrainerCardFront defs, naming them pbBadgeScene and pbDrawTrainerCardBack respectively, and started modifying it to show my new graphics instead. I also mucked around with the text a bit to be doubly sure it was drawing correctly.
So with all that done, I went to try it out in game. Did it work? Nope.avi. The Trainer Card stayed as is, and I noticed that trying to quit that caused it to do so without the usual fade effect. In addition, hitting C (i.e. Enter, C, Space) after having hit A cause the fade to occur, but leave the Trainer Card graphics up until one quit the Pause Menu itself.
Figuring I must have coded the button press thingy wrong, I simply took the calls and stuck them in directly after pbStartScene and pbTrainerCard in the PokemonTrainerCard class. Surely they would run then, if not at button press. Nope.avi.
This time, after exiting the TrainerCard normally, my graphic was finally there. But, like the dodgy regular Card from before, it didn't actually do anything (not even return to the original card) and was effectively just plastered on top of the Pause Menu.
I'm at a loss to understand what I'm doing wrong. I chucked in some Message Windows to track how far through my code it goes, but none of them show up. Can someone please educate me? I've included the relevant code below for reference. Blue indicated additions, while maroon indicates modifications.
TL;DR Holy crap I type a lot.
Cheers, Jim.
As you can probably guess from the topic title, I'm having a n00b problem with some coding. Now, I'm not uninitiated with coding, being a student of programming presently at university, but RGSS remains 99% unfamiliar to me. All I've worked with is Pascal and C.
As such, I figured that with the need to eventually script some major stuff for my game, it'd be best to start small, so I followed the suggestions of many more experienced coders and began work on modifying the Trainer Card script.
My aim was to implement a feature such that when one has the Trainer Card open, pressing the A button (i.e. the Z key) would show a separate screen for the badges, along with their titles (and maybe more, if I have room). Once there, one would simply press B (i.e. Esc or X) to return to the original screen.
So I made a duplicate of the pbStartScene and pbDrawTrainerCardFront defs, naming them pbBadgeScene and pbDrawTrainerCardBack respectively, and started modifying it to show my new graphics instead. I also mucked around with the text a bit to be doubly sure it was drawing correctly.
So with all that done, I went to try it out in game. Did it work? Nope.avi. The Trainer Card stayed as is, and I noticed that trying to quit that caused it to do so without the usual fade effect. In addition, hitting C (i.e. Enter, C, Space) after having hit A cause the fade to occur, but leave the Trainer Card graphics up until one quit the Pause Menu itself.
Figuring I must have coded the button press thingy wrong, I simply took the calls and stuck them in directly after pbStartScene and pbTrainerCard in the PokemonTrainerCard class. Surely they would run then, if not at button press. Nope.avi.
This time, after exiting the TrainerCard normally, my graphic was finally there. But, like the dodgy regular Card from before, it didn't actually do anything (not even return to the original card) and was effectively just plastered on top of the Pause Menu.
I'm at a loss to understand what I'm doing wrong. I chucked in some Message Windows to track how far through my code it goes, but none of them show up. Can someone please educate me? I've included the relevant code below for reference. Blue indicated additions, while maroon indicates modifications.
Spoiler:
Code:
[COLOR=Navy]#CHANGED to include following 52 lines of code; 2353 HOURS 23 JUL 2012
def pbBadgeScene
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
background=pbResolveBitmap(sprintf("Graphics/Pictures/trainercardbgf"))
if $Trainer.gender==1 && background
addBackgroundPlane(@sprites,"bg","trainercardbgf",@viewport)
else
addBackgroundPlane(@sprites,"bg","trainercardbg",@viewport)
end
[COLOR=DarkRed]cardexists=pbResolveBitmap(sprintf("Graphics/Pictures/trainercardbackf"))[/COLOR]
@sprites["card"]=IconSprite.new(0,0,@viewport)
if $Trainer.gender==1 && cardexists[COLOR=DarkRed]
@sprites["card"].setBitmap("Graphics/Pictures/trainercardbackf")[/COLOR]
else[COLOR=DarkRed]
@sprites["card"].setBitmap("Graphics/Pictures/trainercardback")[/COLOR]
end
@sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
pbSetSystemFont(@sprites["overlay"].bitmap)
pbDrawTrainerCardBack
pbFadeInAndShow(@sprites) { update }
[COLOR=DarkRed]
Kernel.pbMessage(_INTL("BadgeScene ran correctly."))[/COLOR]
end
def pbDrawTrainerCardBack
overlay=@sprites["overlay"].bitmap
overlay.clear
baseColor=Color.new(72,72,72)
shadowColor=Color.new(160,160,160)
textPositions=[
[COLOR=DarkRed] [_INTL("Test Badge"),34,64,0,baseColor,shadowColor],
[_INTL("[/COLOR][/COLOR][COLOR=DarkRed]Test Badge[/COLOR][COLOR=DarkRed]"),332,64,0,baseColor,shadowColor],
[_INTL("[/COLOR][COLOR=DarkRed]Test Badge[/COLOR][COLOR=DarkRed]"),34,112,0,baseColor,shadowColor],
[_INTL("[/COLOR][COLOR=DarkRed]Test Badge[/COLOR][COLOR=DarkRed]"),34,160,0,baseColor,shadowColor],
[_INTL("[/COLOR][COLOR=DarkRed]Test Badge[/COLOR][COLOR=DarkRed]"),34,208,0,baseColor,shadowColor],
[_INTL("[/COLOR][COLOR=DarkRed]Test Badge[/COLOR][COLOR=Navy][COLOR=DarkRed]"),34,256,0,baseColor,shadowColor],[/COLOR]
]
pbDrawTextPositions(overlay,textPositions)
x=72
region=pbGetCurrentRegion(0) # Get the current region
imagePositions=[]
for i in 0...8
if $Trainer.badges[i+region*8]
imagePositions.push(["Graphics/Pictures/badges",x,310,i*32,region*32,32,32])
end
x+=48
end
pbDrawImagePositions(overlay,imagePositions)
[COLOR=DarkRed]
Kernel.pbMessage(_INTL("DrawTrainerCardBack ran correctly."))[/COLOR]
end
def pbBadgeCard
loop do
Graphics.update
Input.update
self.update
if Input.trigger?(Input::B)
break
end
end
end
#END CHANGE[/COLOR]
def pbTrainerCard
loop do
Graphics.update
Input.update
self.update
if Input.trigger?(Input::B)
break
end
[COLOR=DarkRed]# if Input.trigger?(Input::A) #CHANGED to include Input::C trigger + 9 lines; 0104 HOURS 24 JUL 2012
#
# @scene.pbBadgeScene
# @scene.pbBadgeCard
#
# Kernel.pbMessage(_INTL("BadgeCard call ran correctly."))
# end [/COLOR]
end
end
def pbEndScene
pbFadeOutAndHide(@sprites) { update }
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
end
class PokemonTrainerCard
def initialize(scene)
@scene=scene
end
def pbStartScreen
@scene.pbStartScene
@scene.pbTrainerCard
@scene.pbEndScene
[COLOR=DarkRed]# @scene.pbBadgeScene
# @scene.pbBadgeCard
# @scene.pbEndScene[/COLOR]
end
end
TL;DR Holy crap I type a lot.
Cheers, Jim.