Been stack on a click-to-move player issue for some time

Hey guys,

I am trying to create a turn-based, click-to-move rpg, and been stack for awhile on the actual functionality. I will appreciate any help you can give me. Mind you, I consider myself to be a very slightly above full GDevelop 5 beginner, so a bit more explanation might be needed :slight_smile:

Description:

Please consider the following screenshot:

  • The game has near 400 way markers spread across a map.
  • The player is allowed a certain range “per game turn”.
  • Player can only move to “reachable” locations (green animation) on click.
  • Once player reaches any of the markers within his range, the rest of his “game turn” is forefiet. So in essence, even though the player can have more than one markers within his range, he can only “land” on one per turn.
  • Once player lands in a way marker, a pop-up … “pops up”.

Issue:

I have already figured out how to change the “reachable”/“unreachable” change of animation, by measuring the distance between the player object and the way marker (as you can see from the screenshot). I even figured out a way (and i am proud of myself for that, even though to you, professionals it might look as a child’s play :stuck_out_tongue: ) to limit the movement of the player object to only available way markers by measuring the distance between the cursor at place of click and the player.

Where I am stuck, however is how to move the player to the clicked location and how to detect the clicked location without pathfinding. First I thought that I will write instance variables to all way markers, but the custom settlement markers will be unique (city and town names, etc…).
Then I thought applying pathfinding and hidden obstacles, but I don’t know how to limit the movement “per game day”, i.e. have something like 300 pixels “per day” so once the player icon has “travelled” 300px, it stops, no matter how many times you click, until you “End the turn”. And then i got lost … :smiley: so I thought I will ask the nice smarter than me people of the GDevelop forums for help.

Finally, if this helps, what im trying to achieve can be seen in this half pseudo / half js code :smiley:

FOR EACH way marker CLICKED
CHECK IF
marker has “reachable” animation
player is within the allowed distance
THEN
move player to the clicked location
remove the rest (if any left) of the allowed “game turn” distance

WHEN player “lands” on a way marker
CHECK the object instance variable name
IF object instance variable name is normal way marker
THEN DO
something, something …
ELSE IF not normal way marker
THEN DO
something, something …

there is so many questions.
1, I would use the bult-in pathfinder.
2, you can add as many instance variable to an instance, as you want. even it isn’t use it. just leave the value empty.so you can add the same variables to the standard and the unique markers too.
3, you know what you want to achieve, and your code is almost done. why aren’t you implement that? i can’t see where you are stuck. :face_with_monocle:

Hi mate, thanks for the answer

I’ve figured out the movement bit of the player, now I only need to figure out how can i detect on which marker the player has landed…

In essence, how can i do $(this) in GDevelop5 ?

adding a variable “ID” to each instance? and store it’s value in a scene variable? and then read from there if needed?

As far as I’m aware, there isn’t an equivalent of “this” in GDevelop, because it natively does that via conditions.

For example:
You have 20 objects named “TestObj”, all spread acrossed your scene
You have a condition that says:
“If Cursor/Touch is on “TestObj””

You then have an action that says
“Modify the value of Global Variable “ObjectLocationX” with “TestObj.X()””

Gdevelop will automatically target only the object that the cursor is on.

2 Likes

Much appreciated mate … I don’t know if i did it correctly, but I certainly got the result im after right now :slight_smile:

1 Like