Author Topic: [DONE] Run a function from hyperlink tag  (Read 1225 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

[DONE] Run a function from hyperlink tag
« on: May 24, 2017, 02:00:42 AM »
For the tutorial I would like to be able to create a text that says "next step", and when pressed it executes a certain function, in this case proceed to the next step of the tutorial.

Something similar to the hyperlink tag.

That would be an escape route in case the tutorial is locked in any chapter / step.  8)
« Last Edit: May 26, 2017, 07:16:20 AM by Dwachs »

Offline Yona-TYT

Re: Run a function from hyperlink tag
« Reply #1 on: May 26, 2017, 02:41:21 AM »
This can be one of those functions that return quickly.  8)

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4252
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Run a function from hyperlink tag
« Reply #2 on: May 26, 2017, 07:16:06 AM »
This is in r8242. Usage:
Code: [Select]
<a href="script:bla(19)">HERE</a>

If the string should not contain >,',". Please report any crashes, which might happen with ill-formed strings.
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #3 on: May 27, 2017, 01:08:59 AM »
Many thanks, I will be very happy using this. ;D

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #4 on: May 27, 2017, 11:09:33 AM »
I do not know how to make it work.

This was my best attempt:
Code: [Select]
text.sc = "<a href=script:"+this.next_step()+">HERE[/url]"

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4252
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: [DONE] Run a function from hyperlink tag
« Reply #5 on: May 27, 2017, 03:30:37 PM »
What does ``this.next_step()'' return? What is the content of text.sc after this assign statement?

Edit: The argument of href must be enclosed in quotes like
Code: [Select]
<a href='script:bla(99)'>blub</a>
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #6 on: May 27, 2017, 10:21:26 PM »
What does ``this.next_step()'' return? What is the content of text.sc after this assign statement?
It's just crazy of me. :P
Edit: The argument of href must be enclosed in quotes like
Code: [Select]
<a href='script:bla(99)'>blub</a>
Why is a value sent to the "bla ()" function? Works without needing that number.  ???


One small detail, the function does not show a popup window when a value other than null is returned.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4252
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: [DONE] Run a function from hyperlink tag
« Reply #7 on: May 28, 2017, 12:44:26 PM »
Why is a value sent to the "bla ()" function? Works without needing that number.  ???
This was just to demonstrate that you can pass arguments to the function ;)
Quote
One small detail, the function does not show a popup window when a value other than null is returned.
The return value is not processed. There will be a popup only if some error occured when compiling the code after 'script:'
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #8 on: May 28, 2017, 06:07:20 PM »
There are some moments when you can not skip step / chapter (scenario can be damaged), it would be nice to be able to show some message on the return.Otherwise, players will click repeatedly without knowing why nothing happens.  ;)

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: [DONE] Run a function from hyperlink tag
« Reply #9 on: May 29, 2017, 08:56:23 PM »
Can't the function being called check what value will be returned and show a message if it notices it's an error?

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #10 on: May 30, 2017, 12:43:50 AM »
Can't the function being called check what value will be returned and show a message if it notices it's an error?
Similar to the return of "is_convoy_allowed" to name an example. ;)
By the way I'm very happy with "is_convoy_allowed".  ;D

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4252
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: [DONE] Run a function from hyperlink tag
« Reply #11 on: May 30, 2017, 06:08:27 AM »
If the click would trigger an error, why put the scripted link in the text?
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #12 on: May 31, 2017, 03:44:52 AM »
If the click would trigger an error, why put the scripted link in the text?
I do not mean an error as such, I mean the return value when this is different than null.
Example:
Code: [Select]
    function script_text()
    {
        if (!correct_cov)
            return translate("You can not advance of step at this time.")
        else
            return null
    }



You can test script-text in the tutorial: http://files.simutrans.com/index.php/s/zuwwVADjzLYdki6   ;)
« Last Edit: May 31, 2017, 06:48:06 AM by Yona-TYT »

Offline Yona-TYT

Re: [DONE] Run a function from hyperlink tag
« Reply #13 on: July 05, 2017, 12:18:26 AM »
It seems a bit strange that this is the only function (immediate return) that does not show a popup.  ???