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 ... 64 65 [66] 67 68 ... 78

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

Farseer

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #975 on: February 22, 2011, 07:19:10 am »

Man, I suck at this coding stuff.

I can't work out what's wrong with this:-
Spoiler: continuestory Function (click to show/hide)

Variables, place in code etc:-
Spoiler: Variables (click to show/hide)

Spoiler: Place in Code (click to show/hide)

The trouble is that it just doesn't work. It doesn't end the loop that I need it to. I tried replacing the prologuecont = continuestory() with prologuecont = input, but that didn't seem to work either.

I'm in Python 2.7.2. Any ideas, guys?

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #976 on: February 22, 2011, 07:34:14 am »

I got 50/50 odds, input returns string-type input

try printing the result of 'input' to check the type.
Casting the result to an integer, then printing the integer.
« Last Edit: February 22, 2011, 08:06:12 am by eerr »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #977 on: February 22, 2011, 01:37:00 pm »

That's not the problem (well it may be, but there's a more pressing problem). The problem is that in continuestorymenu (have you considered using CamelCase or dashes in your function names yet?) prologuecont is a local variable, so assigning a value to it will not change prologuecont1 and thus the prologue loop will never terminate. To solve this the simplest way would be to just change prologuecont1 directly incontinuestorymenu.
Another option would be to give continuestorymenu a return value that indicates if the loop has to terminate and then bind the prologuecont1 to the return value. That would also get rid of the need to have prologuecont1 as a global variable.
« Last Edit: February 22, 2011, 01:44:50 pm by Virex »
Logged

Farseer

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #978 on: February 22, 2011, 01:51:52 pm »

(have you considered using CamelCase or dashes in your function names yet?)

That might be a good idea. :p

Another option would be to give continuestorymenu a return value that indicates if the loop has to terminate and then bind the prologuecont1 to the return value. That would also get rid of the need to have prologuecont1 as a global variable.

Thanks, I'll try this out. I'll find out how to do it first THEN try it out. :p

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #979 on: February 22, 2011, 02:38:48 pm »

(have you considered using CamelCase or dashes in your function names yet?)

I find underscores easier to read myself :)
But as long as you use something it doesn't matter too much what.
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

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #980 on: February 23, 2011, 03:47:41 pm »

(have you considered using CamelCase or dashes in your function names yet?)

I find underscores easier to read myself :)
But as long as you use something it doesn't matter too much what.
I've always preferred camelCase, using underscores only rarely (looks too much like a space IMO).
Never used dashes, but IIRC they're not allowed in Java (which I learned first), and old habits die hard. Didn't know they were allowed in python...
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #981 on: February 23, 2011, 03:51:16 pm »

I don't think they're allowed in Python either. I was thinking of underscores.
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #982 on: February 23, 2011, 06:22:53 pm »

I can't believe I haven't looked at this thread before! This is great!

And by that I mean I need help. I'm trying to learn C++ with OpenGL, but it's going really slowly and I'm confused with it. This program is an example from the OpenGL Superbible, but it doesn't work and I'm not sure why.

Spoiler: Block of code (click to show/hide)

It's supposed to make a triangle appear on the screen (which it does) and the triangle is supposed to move up when you press the up arrow (but it doesn't). Could anyone point out what I'm doing wrong? It uses FreeGLUT and GLTools.

Also, if this isn't the kind of thread where you post stuff like this, my bad. Sorry.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #983 on: February 24, 2011, 04:57:27 am »

Code: [Select]
void SpecialKeys(int key, int x, int y)
{
   GLfloat stepSize = 0.025;

   GLfloat blockX = vVerts[0];
   GLfloat blockY = vVerts[7];

   if (key == GLUT_KEY_UP)
   {   blockY += stepSize;}

   vVerts[0]=blockX;
   vVerts[1]=blockY;

   vVerts[3]=blockX;
   vVerts[4]=blockY;

   vVerts[6]=blockX;
   vVerts[7]=blockY;

   vVerts[9]=blockX;
   vVerts[10]=blockY;

   squareBatch.CopyVertexData3f(vVerts);

   glutPostRedisplay();
}

You want to modify the vertex buffer of triangleBatch, not squareBatch (which I assume is just an accidental leftover of prior experiments). Plus you're sort of adding vertices to it (you have nine but are indexing eleven) which will end badly. Only reason this doesn't crash and burn badly is because your renderloop is only drawing the unmodified triangleBatch.
« Last Edit: February 24, 2011, 04:59:23 am by olemars »
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #984 on: February 24, 2011, 01:34:37 pm »

You want to modify the vertex buffer of triangleBatch, not squareBatch (which I assume is just an accidental leftover of prior experiments). Plus you're sort of adding vertices to it (you have nine but are indexing eleven) which will end badly. Only reason this doesn't crash and burn badly is because your renderloop is only drawing the unmodified triangleBatch.

The part about squareBatch is confusing to me; in the book I'm getting the example out of, it says square instead of triangle. Same with the extra vertices. Weird. Maybe I just misread it or something...

Anyway, now the program actually does something! Hooray! Although I'm not sure why the triangle disappears instead of moving, but still.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #985 on: February 24, 2011, 01:44:08 pm »

You could have the vertices defined the wrong way around in the movement code, which would cause the backface culling to kick in.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #986 on: February 24, 2011, 02:09:45 pm »

You want to modify the vertex buffer of triangleBatch, not squareBatch (which I assume is just an accidental leftover of prior experiments). Plus you're sort of adding vertices to it (you have nine but are indexing eleven) which will end badly. Only reason this doesn't crash and burn badly is because your renderloop is only drawing the unmodified triangleBatch.

The part about squareBatch is confusing to me; in the book I'm getting the example out of, it says square instead of triangle. Same with the extra vertices. Weird. Maybe I just misread it or something...

Anyway, now the program actually does something! Hooray! Although I'm not sure why the triangle disappears instead of moving, but still.

The example was probably a square at first, but then they decided on a triangle instead and forgot to edit the whole example.

It disappears because
Code: [Select]
   GLfloat blockX = vVerts[0];
   GLfloat blockY = vVerts[7];

   if (key == GLUT_KEY_UP)
   {   blockY += stepSize;}

   vVerts[0]=blockX;
   vVerts[1]=blockY;

   vVerts[3]=blockX;
   vVerts[4]=blockY;

   vVerts[6]=blockX;
   vVerts[7]=blockY;

here you assign blockX to all x coordinates (vVerts[0], vVerts[3], vVerts[6]), in practice making your first and second vertice have the exact same coordinates and also shifting the third to the left
. You really don't have to assign to the X coordinate at all since you're not moving along that axis.

EDIT: Misread it a little. In fact you're assigning the same coordinates to all three vertices, forming a single dot.
« Last Edit: February 24, 2011, 02:24:10 pm by olemars »
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #987 on: February 24, 2011, 05:12:52 pm »

EDIT: Misread it a little. In fact you're assigning the same coordinates to all three vertices, forming a single dot.

Good catch, didn't even see that. He probably should just change the 'Y' verts to be += stepSize directly and be done with it, I'm not sure what the setting blockY first is trying to do.
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

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #988 on: February 24, 2011, 07:00:14 pm »

Also, if this isn't the kind of thread where you post stuff like this, my bad. Sorry.
As you can see, you're in the right place :)
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))

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #989 on: February 25, 2011, 03:32:22 pm »

A potentially useful resource for non/new-coders who want to learn programming: http://learnpythonthehardway.org
Obviously this will teach you python but apparently it's a good grounding in how people learn to program, I've not read it but enough people I know have recommended it that I thought I'd pass on the link.
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
Pages: 1 ... 64 65 [66] 67 68 ... 78