News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

[patch] New script function for coordinate links

Started by Yona-TYT, August 22, 2021, 12:00:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

This patch adds a script function that will be called each time you click on a link to coordinates, while sending the cord to where the link is aimed.
This is to use it in the tutorial, if there is no problem.  :P

prissi

Sorry what purpose fullfills "is_link_go_to_pos" Isn't there a jump to position tool?

Yona-TYT

Quote from: prissi on August 22, 2021, 02:53:10 AMSorry what purpose fullfills "is_link_go_to_pos" Isn't there a jump to position tool?
It is not to jump position, it is to make a call or script event every time a link is clicked.

If a value other than null is returned in the script, it will display a message.

prissi

Sorry, I am still not clear of the purpose. There are no links in simutrans. What do you mean?

Yona-TYT

Quote from: prissi on August 22, 2021, 02:18:14 PMSorry, I am still not clear of the purpose. There are no links in simutrans. What do you mean?
I think I have given this a bad name, by link I mean:
"<a href=\"("+pos.x+","+pos.y+")\">" + "Link name [/url]"
Which represents a link in the information window of the scenario, when you click it, it jumps to the position "(pos.x, pos.y)" on the map.

The function in question is to obtain the coordinate "(pos)" when clicking on said link and perform any action within that function from the script api.

I can, for example, make it point to a monument, then through that function from the script api I make all the tiles of the object (the monument) be marked and unmarked when removing the cursor from the object.

Yona-TYT

Well I leave you a small demonstration of a script using this:  8)
Note: Change the coordinate (pos) to point to a "building" type object.

prissi

#6
The problem with your patch is a cryptic function I have no idea what it does with a conraticting name and comment. According to the very few rules we have
is_xxx(...)
should return a boolean and not change the state. Your comment says this is the jump to position tool. But that is already changed. So your comment is wrong. I guess this is a callback after calling jumping to a position. So it could be called "jump_to_link_executed()" or so. I change the text.

What happens if the script does not provide a function?

Yona-TYT

Quote from: prissi on August 23, 2021, 12:18:14 AMWhat happens if the script does not provide a function?
If you do not provide it, it does not matter, they are optional. ;)
What do you think of "is_jump_to _link _executed ()"?, So it would combine with the others (example "is_convoy_allowed"), by the way, if from the api the return is different from null, show a message using the return.

Mariculous

#8
Such callbacks usually shouldn't be called "is_*"

"is_" is the prefix of boolean getters "get_".
Which means they should return a (potentially calculated) property of an object without changing objects state.
Often, getters pair with a setter. If there is a related setter, then o.set_a(a); o.get_a() == a shall always be true.

At least that's a common convention in OOP.

This function rather seems to be an event listener.
Such use the "on_" prefix in many languages. The name should state when this callback will be called.
"on_click" or "on_link_click" seems fine to me depending on the exact context and purpose.

Yona-TYT

Quote from: Freahk on August 23, 2021, 08:51:34 AMThis function rather seems to be an event listener. Such use the "on_" prefix in many languages. The name should state when this callback will be called. "on_click" or "on_link_click" seems fine to me depending on the exact context and purpose.

well maybe the correct name is "on_jump_to_link_executed" as you say.  :P






I already added this to the pak64 tutorial, now you don't get lost looking for the stops in the list from the Scenario Window, this is great !.   8) https://github.com/Yona-TYT/tutorial_pak64/commit/ac596c20efeaa69ec0594bb99c6acca3aa1ba749