Author Topic: Do you use loops?  (Read 11112 times)

SarahW

  • Newcomer
  • Posts: 33
  • Karma: +0/-0
    • View Profile
    • Email
Do you use loops?
« on: May 24, 2016, 06:04:11 PM »
I tried looking for specifics in a startpage search, but usually when I look up specific things Stack Overflow often gives confusing answers without really explaining how anything works, and then I have figure out how to rework things to fit in a game design concept. Very frustrating.

Anyway, what I mainly know of Ruby is strings, variables, arrays, class, class call. I have difficulty with more specific grhings like reading files, so I often end up having to hard code levels in.

Is there a way to find tutorials written in a way that don't feel like machine level language? That way I can better find out the extent of which specific loops in Ruby are necessary.

Code: [Select]
class Hello

  def initialize
    greet
  end

  def greet
    puts "Hello Roguelike Forums."
  end

end

Hello.new

Mostly used to novels, so this has been an ... interesting experience so far.

Tzan

  • Rogueliker
  • ***
  • Posts: 193
  • Karma: +0/-0
    • View Profile
Re: Do you use loops?
« Reply #1 on: May 24, 2016, 08:59:13 PM »

Trystan

  • Rogueliker
  • ***
  • Posts: 164
  • Karma: +0/-0
    • View Profile
    • my blog
Re: Do you use loops?
« Reply #2 on: May 25, 2016, 01:50:37 AM »
Ruby code usually uses the `each` method on collections instead of explicit loops.

Code: [Select]
items = ["sword", "shield", "armor"]

items.each do |item|
   puts item
end

SarahW

  • Newcomer
  • Posts: 33
  • Karma: +0/-0
    • View Profile
    • Email
Re: Do you use loops?
« Reply #3 on: May 25, 2016, 02:34:17 AM »
Ruby code usually uses the `each` method on collections instead of explicit loops.

Code: [Select]
items = ["sword", "shield", "armor"]

items.each do |item|
   puts item
end

Thanks! I'll look into that.

I am familiar with things like:

Code: [Select]
20.times do
  puts "Hello World."
end

So I'll be sure to test it out!

kipar

  • Rogueliker
  • ***
  • Posts: 105
  • Karma: +0/-0
    • View Profile
    • Email
Re: Do you use loops?
« Reply #4 on: May 25, 2016, 05:20:00 PM »
There is also more classic
Code: [Select]
while condition
...
end
for algorithms
and even infinite
Code: [Select]
loop do
...
end
for things like a main game loop.

SarahW

  • Newcomer
  • Posts: 33
  • Karma: +0/-0
    • View Profile
    • Email
Re: Do you use loops?
« Reply #5 on: May 26, 2016, 10:58:46 PM »
Would that be like for a game engine?

One of the first text based games (not going to say it's roguelike, cause ... well it's not.) was a hybrid of text based adventure and an early navigational style. I've sense learned better methods (not pun intended) like assigning tiles to variables and navigating based on a game loop in a game class.

Note to self, contains navigation in one method.

Central Hud is what I use for more statistics based games. It's closer to a text based "dating sim" than a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Do you use loops?
« Reply #6 on: May 27, 2016, 07:16:56 AM »
These AI bots are getting interesting. It's almost making some kind of sense.

AgingMinotaur

  • Rogueliker
  • ***
  • Posts: 805
  • Karma: +2/-0
  • Original Discriminating Buffalo Man
    • View Profile
    • Land of Strangers
Re: Do you use loops?
« Reply #7 on: May 27, 2016, 11:42:07 AM »
Yup. Too bad our local flame bot can't muster anything reminiscent of intelligence, though.

As always,
Minotauros
This matir, as laborintus, Dedalus hous, hath many halkes and hurnes ... wyndynges and wrynkelynges.

jere

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 233
  • Karma: +0/-0
    • View Profile
    • Email
Re: Do you use loops?
« Reply #8 on: June 03, 2016, 03:12:44 PM »
Yea, I've read this thread a dozen times and I still can't tell if SarahW is a bot. It's hard to believe that some of the sentences are from a bot, but other sentences are pretty incoherent. Maybe it's some combo of markov generation and a human writing? No idea.

Anyway, loops are one of the most fundamental constructs in programming. I can't image doing much useful without them, especially for games programming. And they're pretty easy too.

My biggest problem with loops is when I often try to delete out of array I'm looping over. Only works if the loop runs in reverse.
Golden Krone Hotel -- available on Steam Early Access now