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.

infinite loop

hey, i'm fairly new to scripting in ruby, and i'm confused why i'm getting stuck in an infinite loop when i shouldn't be.


all i have in my scripts is

class BayoScript
  def main
    p "Hello World"
  end
end

... and i'm confused why that would infinite loop. its begin called by an action button event simply using

$scene = BayoScript.new

I've check if the event is being called multiple times but it isnt, it only calls that line once.

This is proberly an easy issue to solve, i've looked around the forums a fair bit but couldn't find a solution.

kindof feels weird to ask such a simple problem when i have a degree in c++ >_> lawl
 
Ok. The very last script section in the editor is part Main. It's code looks something like this:

Code:
$scene = Scene_Title.new
while $scene != nil
  $scene.main
end

So therefore, rmxp is run in an infinite loop calling the main method of whatever $scene is until $scene is Main. So by setting $scene = BayoScript.new, your main method gets called over and over. Hope that helped.
 
ah kks yeah that makes sense. i just assumed it would end the script and then exit back out into the game.

i'm guessing i need to set my $scene back to what it was previously at the end of the function. unless i can just call a script without changing the scene.
 
Bayo, good guess!  :scruff:

Seph, it's nice having you back. I seem to learn a little something from each post.

Of course, if I had bothered to read the Object class, I would have known there was a 'class' method that returned the class of the object from that class.  "Call me when you have no class!"

Bayo, happy scripting!
 

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