Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 194 195 [196] 197 198 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887369 times)

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2925 on: September 20, 2012, 07:03:59 pm »

Ah, you're right. Good point.

Though I must warn, as I work with pointer arrays a lot: Don't use pointer arrays. Use vectors, or maps, or anything other than your standard array. I've had way too many goddamn bugs arising from keeping track of the damn things as I move them around in memory, and it's just much easier to let one of the standard data containers do it.
« Last Edit: September 20, 2012, 07:07:12 pm by kaijyuu »
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2926 on: September 20, 2012, 07:28:03 pm »

Spoiler (click to show/hide)

lol @ typing without thinking,  what a dumb way to ask that, that obviously wouldn't have worked,
I meant "SDL_Surface* VariableName[12];" which is what you said would work, so thank you.


and, I was using the a = b = c = d = n  method for initializing this series of pointers,

SaG = DG = SnG = GSa = DSa = SnSa = GD = SaD = SnD = GSn = SaSn = DSn = SDL_CreateRGBSurface (SDL_SWSURFACE, 64 , 64 , 32, 0,0,0,0);

but it gets a compile-time error

error: no match for 'operator=' in 'DSn = SDL_CreateRGBSurface(0u, 64, 64, 32, 0u, 0u, 0u, 0u)'|

« Last Edit: September 20, 2012, 08:47:28 pm by Valid_Dark »
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.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2927 on: September 20, 2012, 10:31:36 pm »

Spoiler (click to show/hide)

lol @ typing without thinking,  what a dumb way to ask that, that obviously wouldn't have worked,
I meant "SDL_Surface* VariableName[12];" which is what you said would work, so thank you.


and, I was using the a = b = c = d = n  method for initializing this series of pointers,

SaG = DG = SnG = GSa = DSa = SnSa = GD = SaD = SnD = GSn = SaSn = DSn = SDL_CreateRGBSurface (SDL_SWSURFACE, 64 , 64 , 32, 0,0,0,0);

but it gets a compile-time error

error: no match for 'operator=' in 'DSn = SDL_CreateRGBSurface(0u, 64, 64, 32, 0u, 0u, 0u, 0u)'|

All of those variables are of type SDL_Surface*, correct? If so, there shouldn't be an issue, except that you would have a lot of pointers pointing to one memory location, rather than several pointers pointing to several memory locations. Not sure if that's what you want or not.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2928 on: September 21, 2012, 12:55:04 am »

yeah, I need them pointing to separate memory locations, so I guess I will/can initialize them all on separate lines or do an array
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.

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2929 on: September 21, 2012, 12:57:57 am »

I'd keep what you have there and initialize them all to NULL. Then do whatever other initializations you want.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2930 on: September 21, 2012, 02:52:20 am »

So I'm following this Python tutorial and during the Dictionary lesson it gives this code:
Code: [Select]
matrix = {(0, 3): 1, (2, 1): 2, (4, 3): 3}
print(matrix.get((0,3)))

print(matrix.get((1, 3), 0))

When I press 'run' (it uses Activescript) it gives me this:
Code: [Select]
3
3

What did the maker of the tutorial do wrong?

Logged

SethCreiyd

  • Bay Watcher
  • [VESPERTINE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2931 on: September 21, 2012, 04:07:11 am »

It seems to work in IDLE:

Code: [Select]
>>> matrix = {(0, 3): 1, (2, 1): 2, (4, 3): 3}
>>> print(matrix.get((0,3)))
1
>>> print(matrix.get((1, 3), 0))
0
>>> print(matrix.get((2,1)))
2

dict.get should always return the default value provided (or None) if the desired key is missing.  I would guess at some problem in the passing of the key argument.  Your output suggests that it's doing this:

Code: [Select]
>>> print(matrix.get(0,3)
3
>>>print(matrix.get(1,3)
3

If the matrix dictionary is correctly defined and print(matrix.get((2,1))) returns 1 for you, then I'd guess it's some kind of problem with the interpreter not passing the key argument as expected.  If it returns 2, then the other calls to dict.get weren't constructed right.

I'm only a couple months into Python myself, so I could be missing something here.
« Last Edit: September 21, 2012, 04:09:39 am by SethCreiyd »
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2932 on: September 21, 2012, 04:22:44 am »

I can't use IDLE right now, as I'm at my uni and I can't download it here.

I did change the last dictionary thingie (?) from
Code: [Select]
(4,3): 3 to
Code: [Select]
(4,3): "lol" and now it returns "lol" for whatever value I enter. Note that this only seems to be true for tuples. So I assume activescript doesn't like using tuples in dictionaries or something.
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2933 on: September 21, 2012, 10:28:49 am »

How do I actually make a working .py file? I only used ActiveScript so far.
When I create the following in notepad++:
Code: [Select]
print('Hello, World')as a .py file it just open a black box which immaterially implemented legitimately a fraction of a second later closes.
Damn I really need to learn how to spell that word, Chrome isn't even giving me the right word as a suggestion :S
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2934 on: September 21, 2012, 10:33:51 am »

How do I actually make a working .py file? I only used ActiveScript so far.
When I create the following in notepad++:
Code: [Select]
print('Hello, World')as a .py file it just open a black box which immaterially implemented legitimately a fraction of a second later closes.
Damn I really need to learn how to spell that word, Chrome isn't even giving me the right word as a suggestion :S

That is normal!  The program is just exiting immediately after the Hello World output and closing python.  You'd either have to:

- Put an infinite loop at the end of your program.  (ctrl-c to quit then)
- Put a statement requesting user input at the end of your program (I forget how to do this in python).
- Open up the program "cmd", cd to the directory with your python script, and run "python [yourscript]".  Then the window won't close and you can see your output(and errors, which is nice).
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2935 on: September 21, 2012, 10:51:20 am »

Ok, thanks. I actually managed to open it with Idle, with enables me to run it as well. Instead of exiting the program it just gives me those '>>>' options once it is done with stuff.

Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2936 on: September 21, 2012, 03:45:05 pm »

Does anyone know how to use Codelens with Python?
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2937 on: September 21, 2012, 07:31:49 pm »

I'm trying to program a picross solver and it's proving to be quite difficult,
if anyone is looking for a good logic problem / programming challenge, you should give it a try.
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.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2938 on: September 21, 2012, 08:33:52 pm »

Well that looks like an interesting challenge - do you have a set of sample problems Valid_Dark? (Also apparently the proper name for that sort of problem is a nonogram)
Logged

Araph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2939 on: September 24, 2012, 04:49:56 pm »

Anybody here know how to read XML files with JavaScript? I was following the tutorial here, but it isn't working for some reason. What I'm trying to do is make a JavaScript applet that can read character sheets from a game I've been working on and edit them while they're in a more readable format.

Here's my attempt to get it to load a single skill level using a few edited chunks of JavaScript from the tutorial:
Spoiler: character_sheet.html (click to show/hide)
And here's the XML file that's in the same folder as the HTML file:
Spoiler: character_test.xml (click to show/hide)
Does anybody see some obvious error or anything?

EDIT: Ah, crap. Apparently it needs to have file requests be from servers instead of local files. Does anybody know of a workaround?

DOUBLE EDIT: Oh, well. Looks like whoever plays will just be using plain text as character sheets. Assuming anybody actually joins, of course...
« Last Edit: September 24, 2012, 08:10:54 pm by Araph »
Logged
Pages: 1 ... 194 195 [196] 197 198 ... 796