Post new topic    
Liquid Metal Slime
Send private message
Problem using "continue" in script called within p 
 PostThu Dec 18, 2014 1:36 am
Send private message Reply with quote
So I have a plotscript which calls upon another script within it. Nothing wrong with that. The problem is that this script is called within a for loop of the plotscript, thus when I use the function "continue" within the script it's giving me the following error:

"Continue used outside of do() script will be exited"

Technically the "continue" function is within the do() because the do() is calling on a separate script.

Is there a way to fix this?

I figure I could combine the script into my plotscript rather than calling it separately. This would be bothersome though since it would make the plotscript ginormous....
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal Slime
Send private message
 
 PostThu Dec 18, 2014 1:56 am
Send private message Reply with quote
Just for clarification, does your script look something like this?

Code:

script, first, begin
  for(x, 0, 10) do,begin
    second
  end
end

script, second, begin
  # do stuff
  if(condition) then(continue)
  # do more stuff
end
Liquid Metal Slime
Send private message
 
 PostThu Dec 18, 2014 2:00 am
Send private message Reply with quote
Not quite, mine is a plotscript which calls upon a script like this:

Code:

plotscript, first, begin
  for(x, 0, 10) do,begin
    second
  end
end

script, second, begin
  # do stuff
  if(condition) then(continue)
  # do more stuff
end


⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal Slime
Send private message
 
 PostThu Dec 18, 2014 2:05 am
Send private message Reply with quote
There's a couple of things you could do here. The main thing is to get the continue command into the first script. You could do it like this:

Code:
plotscript, first, begin
  for(x, 0, 10) do,begin
    if(second == -1) then(continue)
  end
end

script, second, begin
  # do stuff
  if(condition) then(exit returning(-1))
  # do more stuff
  return(0)
end


If it's feasible, you could also split the second script into two separate scripts.

Code:
plotscript, first, begin
  for(x, 0, 10) do,begin
    second
    if(condition) then(continue)
    third
  end
end

script, second, begin
  # do stuff
end

script, third, begin
  # do more stuff
end
Liquid Metal Slime
Send private message
 
 PostThu Dec 18, 2014 2:10 am
Send private message Reply with quote
I see. Well perhaps I may just have to combine it in to one big script because my second script has about 20 "continue" functions in series which raises the difficulty of solving it any of these ways. It's okay though, I've attempted to make one big plotscript and it works. Hopefully having a giant plotscript doesn't lead me to any struggles later though.

Out of curiosity why can't the "continue" be called like I have described? If you know...
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal King Slime
Send private message
 
 PostThu Dec 18, 2014 2:37 am
Send private message Reply with quote
You can use the 'exit returning' technique Sephy gave regardless of the number of continue statements in the script; no need to inline it.

'continue' and 'break' can't jump across script boundaries because HamsterSpeak is a lexically scoped language, just like most other modern programming languages. That means that the compiler or a human can tell what a script does without looking at any other scripts. Under the alternative, dynamic scoping, a "continue" would behave like an exception, and you can't tell where it's going to jump to.
Liquid Metal Slime
Send private message
 
 PostThu Dec 18, 2014 3:25 am
Send private message Reply with quote
Alright good to know. I guess I don't program much outside of this language so I've never run in to this kind of thing before.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Display posts from previous: