Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 47 48 [49] 50 51 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95939 times)

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #720 on: December 23, 2010, 05:41:01 pm »

It's a tail call (I used tail recursion because that's where it comes up most often), so it ought to work. You're free to prove me wrong though.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #721 on: December 23, 2010, 05:43:26 pm »

Thanks, hopefully this'll work.
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #722 on: December 23, 2010, 09:38:45 pm »

If it doesn't, then it would still be possible to have a central function that switch()s between the rooms, and each room returns the integer ID of the next room (including, possibly, itself, and special codes, like exiting)
Logged
Eh?
Eh!

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #723 on: December 24, 2010, 11:46:02 am »

I don't suppose it's possible to return functions directly in C++? Because that'd solve the headache of maintaining a switcher function.
Scratch that, you can
« Last Edit: December 24, 2010, 11:47:41 am by Virex »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #724 on: December 24, 2010, 12:26:19 pm »

Not only can you return pointers to functions, you can return pointers to pointers to functions, which can return pointers to pointers to functions.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #725 on: December 24, 2010, 12:51:08 pm »



 :D
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #726 on: December 24, 2010, 01:08:29 pm »

Not only can you return pointers to functions, you can return pointers to pointers to functions, which can return pointers to pointers to functions.
I'm not sure why you'd want to do that, but an array of pointers to functions certainly has it's uses as a queue of actions (though you may want to use a heap for that)
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #727 on: December 24, 2010, 07:45:07 pm »

>N
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #728 on: December 27, 2010, 05:19:09 pm »

Small programming dilemma. Should I dynamically (or whatever) create items by having an empty item template and assigning values to it (such as size, weight, value, description etc.) and do that each time, or should I make a list of predefined items and pick one from that?
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #729 on: December 27, 2010, 06:10:59 pm »

Small programming dilemma. Should I dynamically (or whatever) create items by having an empty item template and assigning values to it (such as size, weight, value, description etc.) and do that each time, or should I make a list of predefined items and pick one from that?

Depends on your situation, which I admit is no help at all.

Generally I'd predefine the items if there was relatively few possibilities and I'm likely to be creating and deleting many of them over and over. Your basically treating the item as a constant and creating references / pointers to it in this case.

If your item set is large and varied you might be better of creating them. However if they are the same class but different values there is no reason you couldn't throw them onto a stack once done with them and reuse the memory next time you need a new one, rather than creating and deleting.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #730 on: December 28, 2010, 06:58:38 am »

Currently I have 10 empty "slots" in my player class. Each slot is a class by itself and contains a few variables to make this work, along with some methods. The inventory is an array of these classes, and I give/take items from the player by assigning values to the slots.

The question is whether I'm approaching this the right way. I'll have a large amount of various items, but a problem is whether I can keep them consistent. I don't want a laundry list of items like "soil", "Soil", "Dirt", "Earth", etc. that all mean the same thing.

Besides, what if I want an item with some special values?
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #731 on: December 28, 2010, 07:27:50 am »

you could just make sure there never actually is more than one Dirt.

you are the programmer.

you have the power.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #732 on: December 28, 2010, 07:29:57 am »

Waitwhathow
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #733 on: December 28, 2010, 07:32:24 am »

you chose what items are there.

there is only more than one type of dirt if you put it in there.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #734 on: December 28, 2010, 01:28:02 pm »

Found a neat little article I found about bitwise operators and tricks that can be done with them: http://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign
Been messing with this all day.
Logged
Pages: 1 ... 47 48 [49] 50 51 ... 78