• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Goto line or Restart Script Code

Guest
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Hello all,

I have a script with nearly 600 lines and in a few places within the script there are alerts that tell the user the answers they have given would not work so the script then exits and they need to restart the script manually.

My preference would be that the script automatically re-runs either from the start or from a specified line. Now, years ago on the 48k spectrum I would have wrote something like “goto line xx” and it would happily jump to that line and continue from there (showing my age ).

I have tried using Functions but this over complicates things somewhat and wondered if anyone has a simple ‘goto line’ or ‘restart script’ code to replace the exit() code?

Many Thanks for any help, Brendan

TOPICS
Scripting

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

use Break or continue within functions

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

I'm looking at the link right now to see if I can code the javascript but can I just check if these can be used without 'Functions' as these are what I'm trying to avoid. Would rather just have a code that sends me to the start of the script or maybe a certain line.

Thanks for you reply, Brendan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Functions are your friends. You do not want to be avoiding them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

I have used them in quite a few scripts that I have created but I do find that if you try to add them to an already created script it can cause quite a few variable problems (well for me it does ), my understanding of them isn't fantastic yet so thought a simple goto line might exist... beginning to think the spectrum had it right 35 years ago

Will keep working through to see what can be done.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

I recommend reading up on functions because they WILL simplify things.

Variables are pretty straight-forward. Just declare all your variables using var inside your functions and pass in any others as parameters or attach them to global objects.

It's really not generally advisable (I strongly advise that you become comfortable with functions), but you can use goto in Javascript. Here's a discussion on the topic:

How can I use goto in Javascript? - Stack Overflow

HTH,

Harbs

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

For the record:

I NEVER use labels in Javascript, and I only once saw it in use in respectable code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Hi Brendan,

In short: you can switch to Visual Basic to have GOTO routine, but...

Mixing functions with various loops (for, while, switch) should essentially improve your code.

If you cant see the way of using them - means that things are far too much complicated already.

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

We have moved on from the zx80, zx81, spectrum days.

Clive Sinclair (Spectrum) went bust quite some time ago.

If you want to join him follow the practices of those day if not take Harbs advice

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

LATEST

Well, thanks for the advice Trevor. Will try not to add the background of my logic into my questions again.

A big thank you to everyone else, you've been very helpful and I have been looking at the function way for the past couple of hours to see what I can get working.

Brendan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

This is the type of structure I would like to achieve, although this example would give an infinate loop it demostrates the theory.

alert("BEGINNING")

alert("END")

goto start

alert("THIS ALERT WILL NEVER SHOW")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines