Temple of The Roguelike Forums

Development => Programming => Topic started by: SarahW on May 24, 2016, 06:04:11 PM

Title: Do you use loops?
Post by: SarahW 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.
Title: Re: Do you use loops?
Post by: Tzan on May 24, 2016, 08:59:13 PM
Free version of the book:

http://learnrubythehardway.org/book/index.html


Title: Re: Do you use loops?
Post by: Trystan 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
Title: Re: Do you use loops?
Post by: SarahW 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!
Title: Re: Do you use loops?
Post by: kipar 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.
Title: Re: Do you use loops?
Post by: SarahW 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.
Title: Re: Do you use loops?
Post by: Krice on May 27, 2016, 07:16:56 AM
These AI bots are getting interesting. It's almost making some kind of sense.
Title: Re: Do you use loops?
Post by: AgingMinotaur 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
Title: Re: Do you use loops?
Post by: jere 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.