Ruby/RGSSx questions that don't deserve their own thread

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
You can do that, but be aware that if the player can access the save menu and tries to save the game, the game will crash and the save file will become corrupted, so it gets auto-deleted.
To avoid this, you have to dispose the sprite you assigned to that variable and set the variable to something that is compatible with the Marshal.dump method (it can be a simple nil or false).

Also, having the sprite on screen when the player opens the menu (or changes the scene in any other way) will make the image disappear once the scene is back to the map, but that doesn't mean that the variable is cleared, so it will still hold that sprite.
or i can just use it as normal variable and set some value...
anyway - that game have no save... etc.

In short, you can't just create sprites all over the place, you have to make sure that they are properly disposed when you are done with them or you will get into a lot of issues.

If you get the disposal issue out of the way, here is how you can set the image above/below other things:
Code:
$game_variables[30].z = 50
Just change the value to higher/lower (by +/-50 at a time) to see where it gets placed.
for some reason it did not work :(

====
upd:

I managed to find out that with a value of Z = -1 the picture is drawn under the tiles, and for any values above it - drawn above the character.
 
Last edited:

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
well. I couldn't get an answer to my question in any community ...
and although my knowledge in programming tends to zero, I will probably find the answer myself rather than get help from at least someone, which, frankly, greatly surprises me.

anyway, I continue my research on my own:
and so, I replaced in scripts in class Spriteset_Map

@ viewport1 = Viewport.new
by
$ viewport1 = Viewport.new

(well, throughout the class, respectively).

then, calling a script from an event:

$ game_variables [30] = nil
$ game_variables [30] = Sprite.new ($ viewport1)
$ game_variables [30] .bitmap = Bitmap.new (544,416)
$ game_variables [30] .bitmap.fill_rect (0, 0, 544, 416, Color.new (255,0,0,255))
# $ game_variables [30] .z = 0
$ game_variables [30] .x = 0
$ game_variables [30] .y = 0

drew the same picture between the tiles and the character.

from here I can conclude that direct access to the @ viewport1 variable does not work and it is necessary to access the variable in a different way. but I have no idea how. I hope that there is at least someone who will tell me a solution.
 
Last edited:

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
356
Reaction score
137
First Language
English
Primarily Uses
RMXP
Yes, your problem is the fact that the sprite you are trying to create needs to be on the same viewport as the character you want to be above it. In Spriteset_Map, a lot of things are drawn to @viewport1, such as the Tilemap, Parallax, and characters. This has a natural Z-value of 0. You can initialize a sprite with (Sprite.new(some_viewport)) or without a viewport (Sprite.new). When you don't, the Sprite's Z-value is compared to the viewports' Z-values, NOT the sprites contained within those viewports. Initially, it too has a Z-value of 0. But the rules of order dictate that the most recently created Sprite is drawn on top of everything else of the same Z-value, hence why your picture was always above the character (and everything else drawn to @viewport1). It wasn't until you made it less than 0 that it would be below @viewport1; but now this puts it below ALL THE SPRITES on @viewport1.

So you are correct that you need to initialize your sprite to Spriteset_Map's viewport1 instance variable (that's what the @ in front of variables are called). Instance Variables are only accessible from within the class itself. Global variables (those starting with $) are accessible anywhere, but it's bad practice to use those willy-nilly, a common trap many beginners fall into. What you want to do is make the instance variable accessible from outside of the class by making a get-method for it (AKA readable), which Ruby easily does by using attr_reader , like this:
Code:
class Spriteset_Map
  attr_reader :viewport1
end
However, Spriteset_Map is created by Scene_Map through its instance variable @spriteset, so you need to make it readable as well
Code:
class Scene_Map
  attr_reader :spriteset
end
Now you should be able to reference the viewport in your script calls as follows:
Code:
vp = SceneManager.scene.spriteset.viewport1
$game_variables[30] = Sprite.new(vp)

After that, it's just a matter of adjusting your newly created sprite's Z-value to where you want it. You should also reference the Tilemap class in the Help File as it explains tile Z-values in the Notes section at the bottom. Also know that sprite order is also dictated by Y-value too; sprites closer to the bottom of the screen are drawn above those closer to the top (this is explained in the Sprite class in the Help File).
 

Midnight_Monday

Villager
Member
Joined
Oct 22, 2016
Messages
6
Reaction score
0
First Language
English
Primarily Uses
Does anyone have any information on how to correct the

"Game_BaseItem:29: stack level too deep, SystemStackError"

Specifically searching for this variation turns no results.
 

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
...
like this:
Code:
class Spriteset_Map
  attr_reader :viewport1
end
However, Spriteset_Map is created by Scene_Map through its instance variable @spriteset, so you need to make it readable as well
Code:
class Scene_Map
  attr_reader :spriteset
end
Now you should be able to reference the viewport in your script calls as follows:
Code:
vp = SceneManager.scene.spriteset.viewport1
$game_variables[30] = Sprite.new(vp)

thank you very much.
this is an answer that brings me much closer to my goal.
but something went wrong and the game gives an error (undefined method 'spriteset')
maybe I can figure it out myself, but so far it hasn’t worked. the head just doesn't work anymore - it's the second week I've been trying to create this short script to display the image ><

====
upd:

figured it out. the lines just need to be placed at the beginning of the corresponding classes.
class Spriteset_Map
attr_reader :viewport1

class Scene_Map
attr_reader :spriteset

then it work ^^
Code:
$game_variables[30] = nil
$game_variables[30] = Sprite.new(SceneManager.scene.spriteset.viewport1)
#$game_variables[30].viewport = SceneManager.scene.spriteset.viewport1
$game_variables[30].bitmap = Bitmap.new(544,416)
$game_variables[30].bitmap.fill_rect(0, 0, 544, 416, Color.new(255,0,0,255)) 
#$game_variables[30].z = 0
$game_variables[30].x = 0
$game_variables[30].y = 0
 
Last edited:

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
3,054
Reaction score
684
First Language
English
Primarily Uses
RMVXA
Does anyone have any information on how to correct the

"Game_BaseItem:29: stack level too deep, SystemStackError"
This normally means you have code duplicated somewhere, but could also mean that whatever you did is causing the code to loop back onto itself.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,175
Reaction score
7,395
First Language
Indonesian
Primarily Uses
RMVXA
@idleberry friendly reminder.
Instead of using $game_variables which may affect save file and other issues, you can just create a new global variable, for example

Code:
$my_sprite = Sprite.new
Except you have a good reason why it has to be in the game variables.

Does anyone have any information on how to correct the

"Game_BaseItem:29: stack level too deep, SystemStackError"

Specifically searching for this variation turns no results.
The common issue is usually a duplicated script. See if you have them.
 

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
@idleberry friendly reminder.
Instead of using $game_variables which may affect save file and other issues, you can just create a new global variable, for example

Code:
$my_sprite = Sprite.new
Except you have a good reason why it has to be in the game variables.


The common issue is usually a duplicated script. See if you have them.
yes, I've been warned about this several times already.
but...
1) the game I'm making is small - there is no need to use all the variables provided by the editor. therefore, I see no reason to add more, when you can use the already existing surplus.
2) adding your own variables can cause problems if their name matches something else.
3) in the editor, you can give names to variables (this will not change their number), which will allow you to understand exactly which variable is responsible for what. in your own variables, you can get confused if you call them without thinking.
etc.

I know that variables are cleared when the menu is called and that they can lead to problems with saving.
but my game does not imply menu or save.
I also don't neglect to nil variables after use.

====================

however, variables are one option. in fact, I would like to figure out how to create an event and create a picture in it (not from a file). and the same goes for text output.
again - this will not cause problems with saving, since the game is saved in a single place and there are no such things. but displaying an image through a variable is much easier than through an event - even if I was looking for a solution for two weeks, it's hard to imagine how difficult it will be to find a solution to how to create an image in an existing event. (on the other hand, this will allow you to add pictures other than tiles and charsets there.)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,175
Reaction score
7,395
First Language
Indonesian
Primarily Uses
RMVXA
1) the game I'm making is small - there is no need to use all the variables provided by the editor. therefore, I see no reason to add more, when you can use the already existing surplus.
It is just general good practice, there is a chance that you might forget why and ended up causing problems you don't know.

2) adding your own variables can cause problems if their name matches something else.
Specifically, in this case, it is not.
The reserved global variables names usually started with either $data_ and $game_ plus several variables like $TEST and $BTEST. Except for another script also uses a global variable. Even with that, if you decide to name $my_sprite and that clashed with everything else, it would be funny.

3) in the editor, you can give names to variables (this will not change their number), which will allow you to understand exactly which variable is responsible for what. in your own variables, you can get confused if you call them without thinking.
Specifically, in your case, you're reading a number. You have to look up the variable name to know what it is for. Imagine that you just name your global variable, which would even more readable than just game variable number 30, "what it is? I had to look up"

Tell me, which is more clear
$game_variables[30]
or
$picture_sprite
 

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
Tell me, which is more clear
$game_variables[30]
or
$picture_sprite
1616532698597.png
so the first one for sure. at any time i know that $game_variables[30] is an elevator picture...
and what picture sprite is $picture_sprite i have no idea ^^

and, btw, my game have 8 maps, and just one of it - gameplay map...
so the only problems I have with scripts, but not with working with variables.
 

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
yes, you can just change the name to $elevator_sprite of course.
in this case it is inconvenient for me personally - I prefer to copy and paste lines from events from different locations, simply by changing the event number in the new script. otherwise I will need to change the variable names completely ...

================
(rm vx ace)
Can someone tell me, please, how to write the screen coordinates of the character and events into variables?
I was suddenly answered elsewhere 0o
================
then another question: how to replace color A with color B in the bitmap picture? ><
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,175
Reaction score
7,395
First Language
Indonesian
Primarily Uses
RMVXA
simply by changing the event number in the new script. otherwise I will need to change the variable names completely ...
In this case, you can define
$pictures = []
In the Main process (script editor)

Then you can have
$pictures[30] = Sprite.new
If you really just want to use a number and copy-paste.

then another question: how to replace color A with color B in the bitmap picture? ><
For individual pixel color, you can use .set_pixel(x,y,Color.new(255,255,255))
 

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
For individual pixel color, you can use .set_pixel(x,y,Color.new(255,255,255))
for some reason it doesn't work - pixels don't change color:

Code:
xx=1
yy=1
while xx < 160
yy=1
while yy < 416
#  if $game_variables[30].bitmap.get_pixel(xx, yy) == Color.new(255,0,0,255)
   $game_variables[30].bitmap.set_pixel(xx, yy, Color.new(0,200,0,150))
#  end
  if yy == 32
   yy = 383
  end
  yy += 1
end
xx += 1
end
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,175
Reaction score
7,395
First Language
Indonesian
Primarily Uses
RMVXA
If you mean box, use rect
bitmap.fill_rect(bitmap.rect, Color.new(255,255,255,255))
 

idleberry

Villager
Member
Joined
Mar 8, 2021
Messages
15
Reaction score
2
First Language
russian
Primarily Uses
N/A
If you mean box, use rect
bitmap.fill_rect(bitmap.rect, Color.new(255,255,255,255))
nope. I needed to make the background transparent, leaving the image of the objects intact. it turned out that I was capturing the picture before the screen was completely faded out. therefore the colors were different ...
 

archon325

Villager
Member
Joined
Mar 31, 2021
Messages
11
Reaction score
0
First Language
english
Primarily Uses
RMVXA
Does anyone know why I might be getting an undefined method error when trying to access a variable from another class, especially when I've added an attr_accessor? It's saying undefined method "fire", relevant code is below. It's still a work in progress, but I don't understand why it breaks where it does:

class Skill_Requirements def initialize(actor) @requirements = Array.new(&data_skills.length) @actor = actor @requirements[150] = @actor.fire>5 && @actor.fire_ratio>0.5 #breaks on this line end end
class Game_Actor < Game_Battler attr_accessor :fire attr_accessor :fire_ratio def setup(actor_id) @fire=0 @fire_ratio=0 @skill_requirements = Skill_Requirements.new(actor) end def learn_skill(skill_id) unless skill_learn?($data_skills[skill_id]) && skill_requirements.meets_requirement(skill_id)!=false @skills.push(skill_id) @skills.sort! end end
 
Last edited:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,196
Reaction score
848
First Language
Hungarian
Primarily Uses
RMVXA
When you report an error message, always write exactly what you see, or just screenshot it and show it that way.

If it says "Undefined method 'fire' for nil class", that means your @actor variable is nil, and nil doesn't have the fire method, hence the error. Check if that variable actually gets an actor object by the time it hits the error triggering line.

Also, the setup method in Game_Actor is a default method (at least in VX Ace) and you overwrote it, which means you deleted everything that method had originally, so there is a high chance that you will get many more errors even if you fix this one. You want to alias that method, don't overwrite it.
 

archon325

Villager
Member
Joined
Mar 31, 2021
Messages
11
Reaction score
0
First Language
english
Primarily Uses
RMVXA
When you report an error message, always write exactly what you see, or just screenshot it and show it that way.

If it says "Undefined method 'fire' for nil class", that means your @actor variable is nil, and nil doesn't have the fire method, hence the error. Check if that variable actually gets an actor object by the time it hits the error triggering line.

Also, the setup method in Game_Actor is a default method (at least in VX Ace) and you overwrote it, which means you deleted everything that method had originally, so there is a high chance that you will get many more errors even if you fix this one. You want to alias that method, don't overwrite it.
Thanks for the info, I didn't delete the rest of the code in setup(), I simply didn't include it in my post so that you would have less to read through.

The Error message reads: "Script 'Skill_Requirements' line 13: NoMethodError occured. undefined method 'fire' for #<RPG::Actor:0xea202c0>
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,196
Reaction score
848
First Language
Hungarian
Primarily Uses
RMVXA
That means you passed the wrong object as an argument for your skill requirements object.
You need the Game_Actor object, not the RPG::Actor object, they are different.

The Game_Actor class actually got an actor method that returns the database object of the actor (that is the RPG::Actor object).
To get the Game_Actor object, you should use self for the argument there.
 

Latest Threads

Latest Profile Posts

I should probably be dragged kicking and screaming away from Daz3D... I was playing with 8.1 models and came up with this. Thoughts?
and_remember_tomorrow_miranda_8_1.jpg
If you're an artist of illustrations, you're doing fine.
If you're an artist of writing, you're doing fine.
If you're an artist of programming, you're doing fine.
But if you are all three above (and more) you cannot allow any distractions in your life.
Anyone had school furniture?
After working out some initial confusion, I managed to get Yanfly's Improved Battlebacks successfully working on a test battle, changing the battleback and getting it to scroll during combat. This means that I can have graphically dynamic battles on moving platforms, like the roof of a train or the deck of a ship/airship...
Place Events Like Tiles Through Replacement, & Take Notes Free Form | RPG Maker News #41

Forum statistics

Threads
111,398
Messages
1,060,825
Members
144,744
Latest member
SeroWillo
Top