Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 34 35 [36] 37 38 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100868 times)

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #525 on: February 16, 2012, 02:39:59 am »

Near the end, this link mentions insertBefore(). Would that work?
If there's one of those, there's probably insertAfter() as well, which I think is what the OP was looking for...
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #526 on: February 16, 2012, 02:50:44 am »

Oops. Somehow I interpreted "This doesn't insert code after the tag" as "I wish to insert code before the tag."
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #527 on: February 16, 2012, 08:31:31 pm »

Can anyone direct to/recommend a tutorial for using c++ to program a simple roguelike? Preferably with an easy to use interface library. I've seen a couple of tutorials like this for python but otherwise its been rather barren. I don't want to start a debate over which language is best, but should I be learning python if im interested in rl development?
Logged
This conversation is getting disturbing fast, disturbingly erotic.

Stargrasper

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #528 on: February 17, 2012, 02:25:21 pm »

Can anyone direct to/recommend a tutorial for using c++ to program a simple roguelike? Preferably with an easy to use interface library. I've seen a couple of tutorials like this for python but otherwise its been rather barren. I don't want to start a debate over which language is best, but should I be learning python if im interested in rl development?

If you look hard enough, you might be able to find a mirror of that one roguelike tutorial in C++, but I haven't been able to find a mirror of it in years.  You might look at the programming thread over in General and ask there.  There's some existing discussion with C++ stuff and they'll be overjoyed to get you into libtcod, a commonly used roguelike library.
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #529 on: February 17, 2012, 03:30:18 pm »

if you mean the terror in ascii dungeon tutorial here's a link
http://web.archive.org/web/20090202075251/http://cgempire.com/forum/tutorials-101/terror-ascii-dungeon-c-tutorial-codephobes-part-1-a-379.html

doesn't really look like a full tutorial though,
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Rgamer

  • Bay Watcher
  • [RELIGION: JEWISH]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #530 on: February 17, 2012, 08:32:41 pm »

Alright, I'm working on a program to help my buddies and myself play D&D by calculating attack and damage rolls. In order to set the stat modifiers, I'm using an if...else pair for each stat. So I'm wondering, is this structured right?

Spoiler (click to show/hide)

I need nSTRm to be usable in the rest of the program, so do I need to add a return command somewhere?
Logged
Rgamer likes dwarves for their industriousness. He dislikes small dogs for their annoying barking, enjoys a good run, and prefers to consume steak, potatoes, or apples whenever possible. He likes native silver, granite, marble, and ebony.

Stargrasper

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #531 on: February 17, 2012, 08:41:27 pm »

Is that encapsulated in a function somewhere?  Then yes.
Code: [Select]
if (nSTR == 9) {
     return -1;
} else {
     return ((nSTR - 10) / 1);
}

You'll have to call that any time you need nSTRm, something like this...
Code: [Select]
nSTRm = getNSTRm();

Alternatively, you could make nSTRm a global variable or have it as a local variable and just loop over it.  In either of those two cases, your original code looks valid.
Logged

Rgamer

  • Bay Watcher
  • [RELIGION: JEWISH]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #532 on: February 17, 2012, 08:51:31 pm »

Could I just do this:

if(blah)
{
stuff;
return nSTRm;
}

else
{
stuff;
return nSTRm;
Logged
Rgamer likes dwarves for their industriousness. He dislikes small dogs for their annoying barking, enjoys a good run, and prefers to consume steak, potatoes, or apples whenever possible. He likes native silver, granite, marble, and ebony.

Stargrasper

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #533 on: February 17, 2012, 08:54:11 pm »

Yes, that's valid so long as your have declared nSTRm somewhere within that scope ahead of time.
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #534 on: February 17, 2012, 08:55:47 pm »

Instead of a big honking if/else statement, wouldn't subtracting 10 from the score and then returning floor(stat/2) be easier?
« Last Edit: February 17, 2012, 11:07:36 pm by Mephisto »
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #535 on: February 17, 2012, 10:40:42 pm »

I'm slightly confused (done a lot of RPGing, very little of that D&D) about what the actual desired outcome is.

It looks to me that either given a global nSTR value there's a global nSTRm that can be derived (as some kind of "mStatInit()" function to (re)set the globally defined version, or just as a calculation within the constant declaration, immediately after the constant-declaration of nSTR), or you're going to be asking for a new nSTRm for various different nSTRs (in which case, function it all the way, with a "nSTRm = CalcnSTRm(nSTR)" equivalent).

And... the if bit?  At first I thought it was there to "avoid a division by zero", until I read it carefully and saw that this would never be the case and it wasn't there to give a specific defined value for what would have been an undefined (or NaN) result.

Without the special case of the value 9 (which I'll highlight, in the following lists), as far as I can tell the input nSTR values of 7, 8, 9, 10, 11, 12 produce calculated values of -1.5, -1, -0.5, 0, 0.5, 1, respectively, which I presume by casting to the nSTRm with its (presumably) integer type would become -2, -1, -1, 0, 1 and 2, accordingly.  (Round it to nearest, as classically required?  Or does it round it towards zero?  And which behaviour do the sourcebooks require?  These questions may need to be asked, if you don't already know.)  Is the confusion as to rounding the reason for the special case for 9?

(Given that I'm half certain that stats don't naturally dip beneath 8 in the D&D system, I include the base value of 7 for extrapolation purposes only...  But I'm sure a good case of poisoning could bring that value into range if it is to be a dynamic range for both source and calculated versions in the nSTR family (and the other-stat equivalent ones, of course).)

edit: Actually, ninjaed, as I've just now read Mephisto's message, which makes me think he knows something about both the D&D system and is also certain about the natural behaviour of this dialect, where I'd tend to always make sure by using explicit (and hopefully obvious-to-future-reader) methods, regardless of what language I'm currently using.[1]


[1] Doesn't stop me from doing silly things like the following, and all without any comments...
Code: (A Perl function in something I'm just re-writing in another window) [Select]
sub NextPerm {
  for my $i (0..$#_) {
    return 1 if $_[$i]++<$MAX;
    $_[$i]=$MIN;$i++;
  } # END for my $i (0..$#_) {
  return 0;
}
I suppose I could[2] ask for answers on a postcard if you can work out what that's supposed to be doing (and how it used)... And point out the the small mistake that I've just seen which doesn't actually cause it to go wrong, but is a vestigial element left over from a prior re-write, and could have easily caused unexpected problems if I hadn't inadvertently made it not matter at all in this situation. ;)

[2] Not that I am doing, but as I'm trying to demonstrate my sometimes bad coding I really have no reason to prevent you from reply about this, anyway, should you so wish!
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #536 on: February 17, 2012, 10:56:08 pm »

Could I just do this:

if(blah)
{
stuff;
return nSTRm;
}

else
{
stuff;
return nSTRm;

Something that needs to be said about the above.

A) You don't close-} the else.  Probably just a typo, but watch out if you copy back (and de-pseudocode) the above for any reason.
B) You may not even need the else and its {}-block.  You may be able to get away with "if (foo) {doFoo; return FooProduct} doBar; return BarProduct" sort of thing (although better with some line-feeds in it, probably).

What would have been done in the final section of the IfThenElse could safely sit 'in the open' straight after the simpler IfThen, given that a successful If-test sends the process into the Then-block and goes no further with the explicit return being called at that point.

(Assuming I'm not mixing up my code dialects, and it doesn't inexplicably and aggressively attempt all apparently relevant code without any nod to the short-circuiting of the logic train that I'm sure it essentially is.
Logged

Rgamer

  • Bay Watcher
  • [RELIGION: JEWISH]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #537 on: February 18, 2012, 05:01:58 pm »

The reason for the if-else loop is because I need 9 to equal -1. Would just telling it "Hey, give me (#-10)/2" give me -1 if # = 9?
Logged
Rgamer likes dwarves for their industriousness. He dislikes small dogs for their annoying barking, enjoys a good run, and prefers to consume steak, potatoes, or apples whenever possible. He likes native silver, granite, marble, and ebony.

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #538 on: February 18, 2012, 05:38:46 pm »

The reason for the if-else loop is because I need 9 to equal -1. Would just telling it "Hey, give me (#-10)/2" give me -1 if # = 9?

No, but taking the floor of that would. Floor always rounds in the negative direction.
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #539 on: February 18, 2012, 11:36:58 pm »

He could also consider using something like int(#/2)-5, then.

If OP is so concerned to get 9 ending up as -1, I'm thinking that the sourcebook maths/tables probably work on this basis.  Doing an integer division of the whole-number-positive then dragging the lesser numbers into negative territory as much as it drags the higher numbers into not-so-higher territory, but retaining an equal number of multiple-to-one mapping in for all X->Y (in this case, 2 Xs for every Y, something that classically integering (#-10)/2 would not do for the same range.

But, of course, floor's bias towards the more negative/less positive does this.

Anyway, that's a lot of waffle.  (Sub-)Topic closed? ;)
Logged
Pages: 1 ... 34 35 [36] 37 38 ... 91