The International Simutrans Forum

 

Author Topic: [patch] New script function for coordinate links  (Read 430 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
[patch] New script function for coordinate links
« on: August 22, 2021, 12:00:31 AM »
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
« Last Edit: August 22, 2021, 12:33:23 AM by Yona-TYT »

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] New script function for coordinate links
« Reply #1 on: August 22, 2021, 02:53:10 AM »
Sorry what purpose fullfills "is_link_go_to_pos" Isn't there a jump to position tool?

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: [patch] New script function for coordinate links
« Reply #2 on: August 22, 2021, 03:10:56 AM »
Sorry 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.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] New script function for coordinate links
« Reply #3 on: August 22, 2021, 02:18:14 PM »
Sorry, I am still not clear of the purpose. There are no links in simutrans. What do you mean?

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: [patch] New script function for coordinate links
« Reply #4 on: August 22, 2021, 07:18:35 PM »
Sorry, 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:
Code: [Select]
"<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.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: [patch] New script function for coordinate links
« Reply #5 on: August 22, 2021, 08:07:57 PM »
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.
 

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] New script function for coordinate links
« Reply #6 on: August 23, 2021, 12:18:14 AM »
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?
« Last Edit: August 23, 2021, 12:32:36 AM by prissi »

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: [patch] New script function for coordinate links
« Reply #7 on: August 23, 2021, 02:29:45 AM »
What 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.

Offline Freahk

  • Devotee
  • *
  • Posts: 1624
  • Languages: DE, EN
Re: [patch] New script function for coordinate links
« Reply #8 on: August 23, 2021, 08:51:34 AM »
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
Code: [Select]
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.
« Last Edit: August 23, 2021, 09:23:13 AM by Freahk »

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: [patch] New script function for coordinate links
« Reply #9 on: August 23, 2021, 12:09:25 PM »
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.

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