Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 46 47 [48] 49 50 ... 91

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

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #705 on: June 27, 2012, 05:54:55 pm »

I still have no idea how to get any sort of curses to work ._.
Here you go. I used that tutorial to set up PDCurses on Code::Blocks.
So yeah, I don't use Code::Blocks... but I decided I'd go ahead and try this.  Well he installed it a certain way, so this didn't work.  Re-installed Code::Blocks and now when I try to make a new console application it fails to make a file and just doesn't do anything.

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #706 on: June 27, 2012, 06:30:40 pm »

So yeah, I don't use Code::Blocks... but I decided I'd go ahead and try this.  Well he installed it a certain way, so this didn't work.  Re-installed Code::Blocks and now when I try to make a new console application it fails to make a file and just doesn't do anything.
Well of course you must change the file paths to match your own, but aside from that it should work. If you changed the file paths but it still didn't work *shrug* I have no idea what you should do.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #707 on: June 28, 2012, 12:48:43 am »

I'd recommend libtcod over pdcurses if you're new to all this, though. Unlike pdcurses it's actually made to be used for roguelikes.

Also, setting up your development environment, such as IDE, compiler, and getting all that to work, took me ages. I still don't know why al that stuff is still hard. It's easy to be put off by it, perseverance(sp?) is key.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #708 on: June 28, 2012, 01:27:03 am »

I have found cursessharp.dll (plus wrapper) but I cannot find any tutorial or a sample program to learn how to use it. Does anybody know how to work with it in C# in VS2010?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #709 on: June 28, 2012, 02:44:23 am »

Max White would know, but he's been candleja
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #710 on: June 28, 2012, 01:21:28 pm »

Welp, here's the preview of my current movement system (sources are in the archive). Basically it calls a special function which reads the next tile and based on cases provides different results (blocking for walls, opening for doors, various interaction in future for different objects).

Download: http://www.mediafire.com/?r52ca1rr8r10j11



When you press arrowkeys. diifferent functions (go_north(), go_south(), go_west(), go_east()) are called. It may seem that it would be nicer to have a single function for this, but my simple approach allows me to make tiles which can be passed only from certain directions (for example, that's how I simulate the "platform edge" for the metro).

ESC quits the application (with a little prompt).

Please provide feedback if you have time to check :). And god damn it, how do I double-buffer console to stop this flickering? :( :( :(
« Last Edit: June 28, 2012, 01:57:59 pm by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #711 on: June 28, 2012, 01:45:44 pm »

I've found a solution: I only redraw those parts of the screen which are being changed instead of using the Console.Clear().

The map area obviously needs no "clearing" because it's drawn as a rectangle, so it replaces itself.

I should only worry about the long words in the other parts of the screen, like that place which shows the tiles around you.

But is there a better way to do so? Still waiting for someone to tell me how to use curses library in C# :D. PLEASE! :D
« Last Edit: June 28, 2012, 01:53:51 pm by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #712 on: June 28, 2012, 01:57:03 pm »

Hmmm, apparently you can't buffer the console. Two options: Only redraw the tiles that changed, or use a graphical library like curses or libtcod (I recommend the latter for beginners, I made this in 7 days, and I'm not that experienced in game-programming).
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #713 on: June 28, 2012, 02:33:10 pm »

Siquo, did you see this post? Just checking because it's at the end of the page and all that.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #714 on: June 28, 2012, 04:30:06 pm »

Siquo, did you see this post? Just checking because it's at the end of the page and all that.
Yeah no I somehow missed that, sorry. Could you trace the values of xone to xfour just before you call setinterval, to see how they progress?
You could use console.log(xOne, xTwo, xThree, xFour); and then view it in the firebug console (assuming you have firebug and if you don't, install it now and thank me later). It's possible i never becomes one for some reason? 10 as a delay is also a bit... little. It's milliseconds, and having 100 FPS in a browser is always overkill. Try setting it to 100, or at least 40.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #715 on: June 28, 2012, 05:13:52 pm »

And once again, Siquo saves the day! Apparently all of the variables are skipping straight to 0.5 before endlessly looping. Also, setInterval doesn't seem to be causing any delay.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #716 on: June 29, 2012, 02:15:30 am »

Well, you're also using == when..
waitwhat

OOH.

if(x = 1) means TRUE, because any value that is not 0 is also TRUE and variable x has from now on the value 1.
if(x == 1) actually tests whether x has the value 1.

That should clear up a lot :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

GlyphGryph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #717 on: June 29, 2012, 09:19:56 am »

This is why it's always good policy to lead with the constant when not doing assignment.

Don't check "if(x==1)", check "if(1==x)" instead and it will catch a lot of those mistakes that might otherwise slip by.

At least, that's how I've always done it: If Desired Value is the same as Given Value, then...
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #718 on: June 29, 2012, 09:21:28 am »

I understand most of what you've said (not all, especially the syntax of that code unless it's meant to be definined by making special structures as operators for the class
If that was to me (sorry, been offline a couple of days, just catching up) then it's not actual code, in that example, it's just something that's reasonably human-readable/writable (for ease of maintenance by yourself, mainly) that can be machine-read to enact.  You make it any way you wanted, and it'd work like the Raws-parsing bit within DF that "builds an entity" from its body-plan and abilities and other qualities.  (You may be hard-coding the weapon qualities and special abilities within the code, or importing from a file, but either way you'd be working with that textually.)

So, "Dam==Cold:Armour-5" is just text.  Your code goes "There's something to parse..." splits between cause ("Dam==Cold") and effect ("Armour-5") through simple regexp or similar manipulation and then checks to see what the cause consists of.  How you implement it is up to you, but the keyword "Dam"(age) gets interpreted for its various qualities, in each combat round that the weapon (or armour or whatever it is that has this quality) is being used.  I haven't tried to check to see if the rest of your published code might give clues to this, but let's just say that in any given round the "Dam" information includes how much, who from, with what weapon/spell/trap/whatever, and (for the purposes of the above example) any elemental alignment that it has.

The parser you write (I'm leaving a lot of this up to you) will decide that as it is an equality check with the word "Cold", then it checks the true/false condition on Damage.Element="Cold", or whatever might work in your situation.  If it had been "Dam==Orc" then it's receptive towards the Damage.GivenBy (or equivalent) having a value equating with (or including, among other information) an Orc character.  "Dam<50" might interrogate the quantity of damage given, and the parser activates the effect condition only when the damage received is less than (in this case) a value of 50.

If the parser's processing reveals it to be a match, then the effect side is looked at.  In the above example, the effective armour value (for this round only, i.e. due to this particular strike against it) is reduced by five.  As a concept, this represents a weapon that, when attacked by cold-based offensiveness (everything from an icy blast from a wand to being stabbed with an icicle?) acts as a conduit to that kind of attack and thus makes your armour less effective than it is against mundane attacks, or heat-based ones, or water-based ones, etc, etc...  For whatever reason.  Or so I (think) I envisaged that quality.

It could as easily be parsed (should you set it up as such) as a permanent armour adjustment, indicating damage to the armour (spread over the items involved, or applied to one/some of the relevant items?), to the value of five.  Or you might prefer that to be represented as "Armour--5" or "Armour=-5", as what text should be parsed to do that.  It's totally up to you.  (Also consider "Armour.Temp-5" against "Armour-5" so that the "-5" adjustment gets applied to a temporary (during this round's calculations only) armour variable, in the former, while the latter adjusts the situation globally, as appropriate...

But it's a made-up example.  And whatever it looks like "inside the code" (could be more easily readable, or less so), it could be reconstructed in that form from a completely separate RAWs-like or XML-like external configuration file, with yet another format, and yet another parser validating (very importantly!) and then re-encoding the desired effects in the internally-handled method.  Which could be to create a reference to a function.  I could show you several ways of doing this in Perl, but I'm not sure that they'd translate so easily to whatever C-variant you're using (whatever that is, again, I forget).

Oh, go on then... Without any trying of this out, just writing it out on-spec, the test-function creator might look like:

Code: [Select]
sub CreateDamageCheck { # Called whenever a cause of "Dam==something", or other relational variant, is detected
  my ($rel,$qual) = @_; my $test;
  if ($qual=~m/^\d+$/) { # If the quality matches a pure number
    return sub { my ($refDamage) = @_; # $refDamage is for an elsewhere-defined reference to a hash about Damage
      $val = ${$refDamage}{"Amount"}; # I sometimes get the {}s wrong in hashreferences, this may be such an occasion!
      if ($rel eq "==") {return $val==$qual}
      if ($rel eq "!=") {return $val!=$qual} # this sort of thing, for other relationships... could be neater...
    } # END return sub (for damage comparison)
  } # END if $qual is numeric
  if (exists($elemental{$qual})) { # member of (more-)globally defined hash of defined elemental types!
    return sub { my ($refDamage) = @_; # $refDamage is for an elsewhere-defined reference to a hash about Damage
      $val = ${$refDamage}{"Element"}; # I sometimes get the {}s wrong in hashreferences, this may be such an occasion!
      if ($rel eq "==") {return $val eq $qual}
      if ($rel eq "!=") {return $val ne $qual} # Blah-de-blah
    } # END return sub (for elemental comparison)
  } # END if $qual is elemental
  # ...Ditto for checks of $qual against other criteria (although already I can see repeated code that can surely be streamlined!)
} # END sub CreateDamageCheck

So, on getting a "Dam==Cold" match, you'd extract the "==" and "Cold" (may need to do something about case) and effectively set something that was:
Code: [Select]
my $check = CreateDamageCheck("==","Cold")This would(/should, subject to me getting it right!) give a $check that was a reference to an otherwise anonymous function that you could call as:
Code: [Select]
&$check(\%RoundDamage) at every point that the item with this $check stored within it[1] is called.  If it returns a true value, then the &$result() that you created in a similar manner would be called, either acting on combat variables globally within the current scope (bad idea?) or being passed its own \%Whatever full of data (and references of data) to the current combat situation.


But, as I said, this is an untested and on-spec answer, based upon a vague original suggestion, being demonstrated within a language that is not your particular variant of the C-family, and being written without reference to any of your other data structures...  And, like I said, I'm procedurally/functionally/data-orientated, by various degrees, whereas I know your stuff is object-orientated...  So there's an additional sticking point of translation.


(Hmm, not sure if this is a helpful reply at all, then... Probably not.)

[1] Probably you'd take the [$check,$result] two-element array ($result having come from a similar function-creating process to parse the effect string) and stack this cause-and-affect pairing (as well as all others) in the array that is referenced under "special effects".  Whether you process the special-effects queue until you get a valid effect, or process it all (stacking all of them) or even engineer a "case/break" possibility, somehow, is up-to-you...  Actually, it's up to me, as I realise that I'm explaining what I'd do, again, and it probably isn't how you (or any other sane person) would do it.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #719 on: June 29, 2012, 01:00:05 pm »

This is why it's always good policy to lead with the constant when not doing assignment.

Don't check "if(x==1)", check "if(1==x)" instead and it will catch a lot of those mistakes that might otherwise slip by.

At least, that's how I've always done it: If Desired Value is the same as Given Value, then...

For most C++ compilers there are optional warnings you can enable to make it shout angry words at you for doing assignment in a conditional. In 9.998 out of 10 cases it's unintentional so I always enable it and elevate to an error, along with the one for "not all control paths returns a value" and a few others.
Logged
Pages: 1 ... 46 47 [48] 49 50 ... 91