Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved]Catch & Throw (Help out a Newb)

Ok. My Turn. This is about Catch and throw. I have yet to see it actually used in a script, but I have tried reading to understand this concept, but to no avail, I am drawing nil. More or less, I am bored and just wonder what it is and what it could be used for.

Thanks,
The Newb
 

Nava

Member

wow i didnt think i would ever see you ask for help, i was told that you were the best scripter on the site but who knowsss... lol but hey if i could help you i would ill look into it :)
 
lol

I have an idea what it is, but it still just kinda confuses me somewhere between seeing what it does actually comprehending it.

I don't know if I will ever use it, but it's just something I have wanted to know.
 
I don't really know how to explain it, but you can look at the following code, it may help you.

Code:
i = 0
array = []
catch :test do
  loop do
    i += 1
    throw :test unless i < 5
    array.push(i)
  end
end

p i, array # 5, [1, 2, 3, 4]

actually if the condition is met it goes back the the catch and end the loop
 
@Squall: Yeah, that's about as far as I got. I am guessing that the catch syntax starts a block, and basically continues until a condition is met.

But I just want to know, why not use a until loop?



@The Despain: :lol:

By the way, nice Signature
 
Howdy,

I think of Catch Throw as jump instruction found in other lower lever PLs. In many cases what you’re after can be done in a cleaner more stylish way and I have yet never had a need for it. If you still confused compare it to the jump to label in RMXP although not at all logically them same the function is about the same. You start here, hit a jump, jump to there, and continue. I would not worry too much about it. There are more interesting things like “Proc” objects that confuses the willies out of just about everyone….

Take Care,
Near
 
Thanks Guys. It was pretty much as I thought, kinda useless. :lol:

On the other hand, procs are easy if you look at a pretty simple example. They are just kinda like customizable code blocks (bad explanation, but whatever). Not too much more.

Resolved
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top