The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on May 24, 2017, 02:00:42 AM

Title: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT 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)
Title: Re: Run a function from hyperlink tag
Post by: Yona-TYT on May 26, 2017, 02:41:21 AM
This can be one of those functions that return quickly.  8)
Title: Re: Run a function from hyperlink tag
Post by: Dwachs on May 26, 2017, 07:16:06 AM
This is in r8242. Usage:

<a href="script:bla(19)">HERE</a>


If the string should not contain >,',". Please report any crashes, which might happen with ill-formed strings.
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT on May 27, 2017, 01:08:59 AM
Many thanks, I will be very happy using this. ;D
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT on May 27, 2017, 11:09:33 AM
I do not know how to make it work.

This was my best attempt: text.sc = "<a href=script:"+this.next_step()+">HERE[/url]"
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Dwachs 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

<a href='script:bla(99)'>blub</a>
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT on May 27, 2017, 10:21:26 PM
Quote from: Dwachs 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?
It's just crazy of me. :P
Quote from: Dwachs on May 27, 2017, 03:30:37 PM
Edit: The argument of href must be enclosed in quotes like

<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.
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Dwachs on May 28, 2017, 12:44:26 PM
Quote from: Yona-TYT on May 27, 2017, 10:21: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:'
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT 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.  ;)
Title: Re: [DONE] Run a function from hyperlink tag
Post by: An_dz 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?
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT on May 30, 2017, 12:43:50 AM
Quote from: An_dz 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?
Similar to the return of "is_convoy_allowed" to name an example. ;)
By the way I'm very happy with "is_convoy_allowed".  ;D
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Dwachs on May 30, 2017, 06:08:27 AM
If the click would trigger an error, why put the scripted link in the text?
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT on May 31, 2017, 03:44:52 AM
Quote from: Dwachs on May 30, 2017, 06:08:27 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:
    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 (http://files.simutrans.com/index.php/s/zuwwVADjzLYdki6)   ;)
Title: Re: [DONE] Run a function from hyperlink tag
Post by: Yona-TYT 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.  ???