PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
I'm currently trying to put a lightsource on my player when nighttime hits, but I can't seem to map player X coordinates proper. Ive set Player Map X and Map Y into a variable, and they almost work. I've tried Screen X and Y too, but similar failures.
The light source will appear either up in the corner with MAP X, and will appear to the bottom right below my character with Screen X (and does not stay on the Player if I get close to the edge of the map.

Any ideas would much appreciated. Thanks!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
38,425
Reaction score
10,852
First Language
German
Primarily Uses
RMMV
it would have helped if you showed a picture of how you try to use them, because they're working correctly for everyone else.

I assume the problem is that you have wrong assumptions on what map x and screen x is.

1) map xy are the on-map-coordinates in tiles. If you have a map of 100x50 tiles for example your return would be 1-100 for the x-coordinate and 1-50 for the y-coordinate. And that would be based on map position independend on where on the map your screen display currently is.

2) screen xy are the screen-coordinates in pixels. These will completely ignore the map size or where on the map the current display is, but count the pixels to a position on the current screen and depend on the screen size you set with a plugin (if you did so).

depending on how you create light sources, you might need to recalculate between tile coordinates and pixel coordinates.
 

Restart

Veteran
Veteran
Joined
Mar 15, 2019
Messages
848
Reaction score
742
First Language
English
Primarily Uses
RMMV
By default .x and .y tell which tile you're on (counting from tile 0 at the top/left side of the screen). So when you go from a tile at (0,1) to (0,2), it just changes immediately without intervening values

._realX and ._realY will give the location of the character when moving between tiles (so when you walk from a tile at (0,1) to (0,2), you'll see (0,1.25) at some point

.screenX() and .screenY() point at the middle of the bottom of your character's sprite, and show where it is onscreen

(so for a default 48 x 48 pixel sprite, it's going to point at pixel 24 horizontally, and pixel 48 vertically - but NOTE that all sprites are displaced up by 6 pixels relative to the map)

Based on your description, are you using an event as a light, and teleporting it around to your player's location?
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
45,996
Reaction score
16,804
First Language
English
Primarily Uses
RMMV
You need to use Control Variables to set the X and Y position based on the player's MAP X and MAP Y and then immediately position your event. The X and Y position variables have to be updated with each frame. You can't just set them once and then expect them to continually update themselves as the player moves.

This is just a guess, based on other people doing this in the past. If this is not what you've done, then we need to see what you've done, in order to see what's wrong with it. Are you only using events, or are you using a plugin? Which one? What order are they in? Show us your event that is moving the light source.
 

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
Hey everyone, thanks for the responses, here's a simple shot of how I declared these variables, and how I'm using them to draw my lightsource. When I get more time I will go over in depth what everyone has shared with me and try it out, thanks!
 

Attachments

  • ss.png
    ss.png
    119.3 KB · Views: 31

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
38,425
Reaction score
10,852
First Language
German
Primarily Uses
RMMV
how I declared these variables, and how I'm using them to draw my lightsource.
that will never work correctly.

you're getting player coordinates as map coordinates, which are in tiles or in values of small numbers (usually <50 for most maps) and then use them in show picture.
But show picture works with pixel-based screen coordinates, so your show picture will almost always land on the first tile top left. Because the lower right coordinates for show picture need to be in the hundreds (default screen size is 816x624, but max map size is 255x255 tiles.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,941
Reaction score
750
First Language
German
Primarily Uses
RMMZ
You can set the Variables 5 and 6 to the Player Screen Coordinates X and Y, instead of Map Coordinates X and Y.
Than your code could maybe work.
 

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
You can set the Variables 5 and 6 to the Player Screen Coordinates X and Y, instead of Map Coordinates X and Y.
Than your code could maybe work.
I tried that too and it gave me similar issues.
that will never work correctly.

you're getting player coordinates as map coordinates, which are in tiles or in values of small numbers (usually <50 for most maps) and then use them in show picture.
But show picture works with pixel-based screen coordinates, so your show picture will almost always land on the first tile top left. Because the lower right coordinates for show picture need to be in the hundreds (default screen size is 816x624, but max map size is 255x255 tiles.
So how would I remedy this?
 

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
You need to use Control Variables to set the X and Y position based on the player's MAP X and MAP Y and then immediately position your event. The X and Y position variables have to be updated with each frame. You can't just set them once and then expect them to continually update themselves as the player moves.

This is just a guess, based on other people doing this in the past. If this is not what you've done, then we need to see what you've done, in order to see what's wrong with it. Are you only using events, or are you using a plugin? Which one? What order are they in? Show us your event that is moving the light source.
My event is the player, and you're right, I did only declare the players MapX and MapY once. Should I run that in a common event in the background? I tried running it constantly just now, in a parallel event on the map, and it didn't seem to have helped anything. (Both MapX and ScreenX)

I would think thatsetting a Players coordinates to a variable would constantly update with the players movements. I tried this in a loop out of curiousity and it didn't work either. I do use plugins, but to be honest I think this problem has been around since I started this project.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,032
First Language
Tagalog
Primarily Uses
RMVXA
I would think thatsetting a Players coordinates to a variable would constantly update with the players movements. I tried this in a loop out of curiousity and it didn't work either. I do use plugins, but to be honest I think this problem has been around since I started this project.

Variables setting in the events would only set the current value of the objects at the time of setting, they don't give the pointer to the data. So you do need to update them manually each time you need them. If setting it on a parallel process doesnt work, please post a screenshot of your event so that we can see what is wrong with it.

Also, make sure none of your plugins are using the variables that you are using for the X/Y as some plugins require variables and changes them periodically.
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
45,996
Reaction score
16,804
First Language
English
Primarily Uses
RMMV
You are setting the variables to a certain value at that point in the game. You are not linking the variable to some other thing so that it will get updated whenever that other thing changes.

So in a parallel event, you should set the two variables (use ScreenX and ScreenY because that's what Show Picture uses) and then your Show Picture command. In the Show Picture command, assuming the centre of the picture is the centre of the light image, make sure you set the Origin to Centre, and not Upper Left, which is what I see in your screenshot. Depending on the size of the image, using Upper Left will cause the light itself to not be centred on your player.
 

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
Variables setting in the events would only set the current value of the objects at the time of setting, they don't give the pointer to the data. So you do need to update them manually each time you need them. If setting it on a parallel process doesnt work, please post a screenshot of your event so that we can see what is wrong with it.

Also, make sure none of your plugins are using the variables that you are using for the X/Y as some plugins require variables and changes them periodically.
I checked my plugins and turned them off and they don't seem to be the issue. I have a couple screenshots of the event and the result (I tired Map and Screen) As you can see the yellow light to the bottom right of the player will follow the player from that position, but stops when close to the edge of the map. (Ignore the graphics, they're just placeholders) And the picture of the event is really just within my TIME counter, for my time of day (just temporarily)

Oh, and I know it's not an event, but a common event, but I tried it in a parralell event in the map too and same effect.
 

Attachments

  • Screen.png
    Screen.png
    653.6 KB · Views: 14
  • ss.png
    ss.png
    97.7 KB · Views: 14

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
38,425
Reaction score
10,852
First Language
German
Primarily Uses
RMMV
the loop in that event will break everything - why do you have that? especially with move picture commands? That makes absolutely no sense.
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
45,996
Reaction score
16,804
First Language
English
Primarily Uses
RMMV
Yes, I think that could certainly cause problems. Loops within parallel process events aren't a good idea.

Can you redesign this event so it can be done over multiple event pages, using event page conditions rather than conditional branches, and only set the ones that actually do something to parallel process?

You also have a combination of things that only need to run once and not repeat, along with things that do need to repeat. It's usually better to have two events for this rather than using loops - one that runs once then erases itself, and another that continues to run while on the map. Might be a bit tricky as depending on your time system, you could be on this map when the time changes, so you might want that "run once" event to trigger again.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,941
Reaction score
750
First Language
German
Primarily Uses
RMMZ
I made an Example. We can help you adjust it to your needs. Try if the Eventcode works on your End.
Code:
◆Control Variables:#0061 var_pl_screenx = Screen X of Player
◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
◆Show Picture:#1, TitleTitleName, Center ({var_pl_screenx},{var_pl_screeny}), (100%,100%), 255, Normal
◆Loop
  ◆Control Variables:#0061 var_pl_screenx = Screen X of Player
  ◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
  ◆Move Picture:#1, Upper Left ({var_pl_screenx},{var_pl_screeny}), (100%,100%), 255, Normal, 1 frame (Dont mark the Wait Box in Move Picture)
  ◆Wait:1 frame
  ◆
:Repeat Above
 

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
the loop in that event will break everything - why do you have that? especially with move picture commands? That makes absolutely no sense.
The
Yes, I think that could certainly cause problems. Loops within parallel process events aren't a good idea.

Can you redesign this event so it can be done over multiple event pages, using event page conditions rather than conditional branches, and only set the ones that actually do something to parallel process?

You also have a combination of things that only need to run once and not repeat, along with things that do need to repeat. It's usually better to have two events for this rather than using loops - one that runs once then erases itself, and another that continues to run while on the map. Might be a bit tricky as depending on your time system, you could be on this map when the time changes, so you might want that "run once" event to trigger again.
Yeah, I just put it in my TIME system temporarily, because I knew it was always running. I also tried it in my generic night cycle, and a parellel process event on the map. Seems to do the same thing everytime. Perhaps there's something somewhere in my game that's messing it up, so I'll have to be vigilant for it.

Can anyone tell me if this works for them? And if so, what was their process? Because it really seems like it should be a simple thing to implament.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,941
Reaction score
750
First Language
German
Primarily Uses
RMMZ
I would recomment to make the Mechanic first on a new Map.
When all works fine, than try to implement it to your main Parallel Event or let it run when needed in an
extra parallel Event or common Event.
The Time Branches will most likely mess up the picture movement (Just a Guess, cant tell for sure).

Edit: A Loop in a Parallel Event is absolutly fine if it's done correctly. In an earlier MV Version the loop caused trouble when changing eventpage without breaking the loop earlier, that bug got fixed as far as i know.
Thats why you could use the above code in a parallel common Event. When you turn on your Flashlight, you also turn on the condition switch for the common event. But we would need to adjust the code to be able to turn the Flashlight properly off again.
 
Last edited:

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
I made an Example. We can help you adjust it to your needs. Try if the Eventcode works on your End.
Code:
◆Control Variables:#0061 var_pl_screenx = Screen X of Player
◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
◆Show Picture:#1, TitleTitleName, Center ({var_pl_screenx},{var_pl_screeny}), (100%,100%), 255, Normal
◆Loop
  ◆Control Variables:#0061 var_pl_screenx = Screen X of Player
  ◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
  ◆Move Picture:#1, Upper Left ({var_pl_screenx},{var_pl_screeny}), (100%,100%), 255, Normal, 1 frame (Dont mark the Wait Box in Move Picture)
  ◆Wait:1 frame
  ◆
:Repeat Above
Yeah, the loop works fine, however the light still appears down to the right of the player. It does update with player position, but it's really delayed. I'm going to keep trying some stuff. Seems like it really should be more simple than this, but again, it could be something I have going on somewhere else in the game.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,941
Reaction score
750
First Language
German
Primarily Uses
RMMZ
Please show a Picture of your new Eventpage which shows your Code. There should be no delay. That lets me guess that you made a mistake somewhere, or it indicates that the error is happening because something else messes it up.
You could adjust the Picture position like this:
...
◆Control Variables:#0061 var_pl_screenx = Screen X of Player
◆Control Variables:#0061 var_pl_screenx - 20
◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
◆Control Variables:#0062 var_pl_screeny - 40 just experiment with the numbers.

Another Solution would be to make a Picture the same size as visible Screen size and make light source in the middle.
Than show that Picture on coordinates 0 and 0, and make it "Top left" , than it looks if the light is always on your Player because both are in the middle of the screen, but you need to make sure
that the player never reaches the map boarders, because than this solution would stop working. Thats why the solution with the parallel Event centering a Picture on Player is more flexible in my Opinion.
 

PKirkby

Veteran
Veteran
Joined
Oct 26, 2019
Messages
157
Reaction score
19
First Language
english
Primarily Uses
RMMV
Please show a Picture of your new Eventpage which shows your Code. There should be no delay. That lets me guess that you made a mistake somewhere, or it indicates that the error is happening because something else messes it up.
You could adjust the Picture position like this:
...
◆Control Variables:#0061 var_pl_screenx = Screen X of Player
◆Control Variables:#0061 var_pl_screenx - 20
◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
◆Control Variables:#0062 var_pl_screeny - 40 just experiment with the numbers.

Another Solution would be to make a Picture the same size as visible Screen size and make light source in the middle.
Than show that Picture on coordinates 0 and 0, and make it "Top left" , than it looks if the light is always on your Player because both are in the middle of the screen, but you need to make sure
that the player never reaches the map boarders, because than this solution would stop working. Thats why the solution with the parallel Event centering a Picture on Player is more flexible in my Opinion.
So here's my event code. It still makes the lightsource appear a ways to the bottom right of my player, and it (sort of) moves with the player, but again, is delayed.
 

Attachments

  • Screen.png
    Screen.png
    136.3 KB · Views: 7

Latest Threads

Latest Profile Posts

Grading the last exams for this semester and I need a break because I am laughing too hard xD
edit: Video link removed due to well Internet problems making it essentially nothing anyway. :kaoswt:
Sleep logic:
4 hours or less = I feel like I'm dying
5-6 hours: Feeling well rested
More than 6 hours: I feel like I'm dying
Women always say "I want to be spoiled" then get mad when I spoil them. Why would you say that if you didnt actually want to know the ending?


decided to have subclasses work differently in my game. They summon in a partner when you select one. this took some work tho as I had to get the class scene to pop up as a common event instead of straight from the menu. it was the only way to add/remove party members while on the menu screens.

Forum statistics

Threads
131,543
Messages
1,220,654
Members
173,220
Latest member
ZecaVn
Top