Setting a variable when the game starts

I am using a code in the materials section to make sure that the first 5 variables in my project are set when the game starts. This is my code:

class << DataManager alias :some_random_alias_init :init def self.init some_random_alias_init $game_variables[1] = 0 $game_variables[2] = -150 $game_variables[3] = -125 $game_variables[4] = 300 $game_variables[5] = 275 endend(code provided by KockaAdmiralac_FINALLY)

it works, the variables are set when the game starts ... but I discovered another problem.

I'm not sure if this counts as a question about scripting, but the reason I need those variables set when the game starts is because I'm using them for my portrets(they represent the drawing positions for the show_picture command). With this script the variables are changed(I press F9 and I can see they are changed) but the pictures are not drawn on the right positions.

In the Show Picture window I have the Display Position set to Variable, and there I set the variables that I need (In most cases x = game_variables[3] and y = game_variables[1])

I press F9 and game_variables[3] is set to be -125 but the X position in which the image is shown is 0...

I really don't know what to do about this ...
I've moved this thread to VX Ace Support. Please be sure to post your threads in the correct forum next time. Thank you.


You know, you don't need to do this in script. Just create a parallel process event on your starting map that sets the variables, then turns on a self switch with a new page conditioned by that self switch to ensure it doesn't run again.


In your Show Picture command, do you set the origin to the top left, or to the centre?


And do you change the variables throughout the game? If you don't, why are you using variables at all? Why not just use coordinates in the Show Picture command?
In the Show Picture command I have it set to the top left

And yes they change throughout the game, depending on the number of portrets on the screen (if it's one guy then he's centered, if there are 2 they are side to side and so on)
Can you show a screenshot of the Show Picture command in your event, with all the settings as you've used them, and a screenshot of what you see in the game?


Are you using any screen resizing scripts or any "system" or "core" or "engine" type scripts?
Are you using any screen resizing scripts or any "system" or "core" or "engine" type scripts?
I do. I use the Yanfly Engine Ace (the core engine)

And these are the screenshots

11ufg5j.jpg
why did you set the X-coordinate to a negative number?

Do you have that much of a transparent area around the bust on the picture?

The regular method would be to make sure that there is no transparent area other than needed around the bust, and setting the X-Coordinate to zero for a left-corner display (or even slightly above zero for a buffer between the left border and the left part of the picture.

Can you attach the bust? I think we have to see how large the transparent frame on it is to solve this problem.
why did you set the X-coordinate to a negative number?

Do you have that much of a transparent area around the bust on the picture?

The regular method would be to make sure that there is no transparent area other than needed around the bust, and setting the X-Coordinate to zero for a left-corner display (or even slightly above zero for a buffer between the left border and the left part of the picture.

Can you attach the bust? I think we have to see how large the transparent frame on it is to solve this problem.
Does the image size really matter that much?

Well this is the image for that character

fkz5dw.png


Yeah it's big, but that's cause I want the size to fit all the characters. And some of the characters are really big.

2ppkitk.png


Like that guy for example
Yes, the image size matters. Because you set the coordinates based on a top left origin. So if you set it to 0,0 and have a whole bit transparent area to the left of the visible sprite, it's going to push the sprite to the middle of the screen.


You'd be better off setting the coordinates where you want the MIDDLE of the image to be, and use Center for the origin.

Original thread: https://forums.rpgmakerweb.com/threads/setting-a-variable-when-the-game-starts.43839/