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.

A Few Questions :)> Update Methods

Status
Not open for further replies.

OS

Sponsor

Hello all. I would like to know some things about the update method.

1.) Does an Update Method occur every second or every frame? I believe it is every frame, but I just want to be sure.

2.) If I call update within update, does it affect the speed at which the code runs? I mean, look at this code:

Code:
def initialize
   @a = 5
end

def update
  if @bool == true
    @a = 20
    @bool = false
  end
  
  if @a <= 10
    @bool = true
    update
  end

  operations
end

Assume that @a was defined earlier as 0. update is called so that operations won't run unless @a > 10. Does this work without taking an extra frame or second? I guess this is silly to ask, but I was just curious.

Peace!
 
1) Once every frame.

2) If you call a method within itself, you create an infinite loop... won't get you anything besides a stucked game ^_^ Use this code instead:
Code:
def initialize
   @a = 5
end

def update
  if @bool == true
    @a = 20
    @bool = false
  end
  
  loop do
    if @a <= 10
      @bool = true
  #else
  #  @a -= 1  
    end
  end

  operations
end
The substract method confuses me a little and doesn't seem to be any practical, but I kept it... I also added two lines you didn't had, to decrease the variable @a, because you wouldn't get nowhere if you didn't change the value of that integer ^_^
 

OS

Sponsor

@Bluescope: ???? Please look at the code. Update is called within itself ONLY if certain values are true or false. It won't be called again in the second iteration of the update method.

This kinda answers my questions. I'll just assume I can continue with my scripting for now. If I get errors, then I'll know for sure!

Peace!
 
Status
Not open for further replies.

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