News:

Want to praise Simutrans?
Your feedback is important for us ;D.

[DONE] Run a function from hyperlink tag

Started by Yona-TYT, May 24, 2017, 02:00:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

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)

Yona-TYT

This can be one of those functions that return quickly.  8)

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Many thanks, I will be very happy using this. ;D

Yona-TYT

I do not know how to make it work.

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

Dwachs

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>
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

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.

Dwachs

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:'
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

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.  ;)

An_dz

Can't the function being called check what value will be returned and show a message if it notices it's an error?

Yona-TYT

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

Dwachs

If the click would trigger an error, why put the scripted link in the text?
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#12
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   ;)

Yona-TYT

It seems a bit strange that this is the only function (immediate return) that does not show a popup.  ???