Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 459 460 [461] 462 463 ... 796

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

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6900 on: January 21, 2015, 01:40:45 pm »

Yeah, I fixed them all.
I couldn't figure out how to forward-declare those template functions (im never going to use two-dimensional arrays again btw, these templates are only necessary because of them but i can't be arsed to rewrite it) so I just moved them up, and replaced the switch with an else-if chain, which is incredibly hacky but works.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6901 on: January 21, 2015, 02:30:10 pm »

Being more specific wouldn't work - when it first encounters "block" it has no context for what you are calling a block - it could be a variable name, a class, a typedef, a macro etc, pretty much anything that can be given a name. You can't assume that the compiler will know what sort of syntax element you mean. Often when we say we'd like a more specific error message it relies on our meta-knowledge of the program's intent which the compiler does not possess.

When it says "int assumed" it's saying it's read "block" to be a variable name, and it attempts to instantiate it as "int block" by default. That makes the * bit following it to be a syntax error. By default the compiler assumes unfamiliar names are variables.

"block *tet;" could be a pointer variable of type "block". but remember * is also multiplication, so "block *tet;" is also a completely valid c++ statement of variable "block" times variable "tet". So, the compiler has no way of knowing whether you forgot to declare two variables which are being multiplied, or you forgot to declare a type which is getting a pointer.

Theoretically, the compiler could be designed to do look-ahead in all source files in the project, just in case the unfamiliar name in one cpp file is a type defined somewhere else, and some scripting languages do allow that. But it would be a fucking amazingly shit way to do things on large or complex projects - every typo could add several minutes to the compile time while it works out that you just had a spelling mistake and weren't referring to some class somewhere.
« Last Edit: January 21, 2015, 02:56:59 pm by Reelya »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6902 on: January 21, 2015, 03:21:06 pm »

I understand how it works, I was just being dumb and forgot that it's a good idea to declare them at the start of your file to avoid headaches. :P
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6903 on: January 21, 2015, 03:33:18 pm »

Later languages like C# have been designed so that they can be 2-pass compiled, i.e. it is extremely obvious from the language grammar when a word is a type that just hasn't been encountered before, because there's nothing else it could be. Which means the source can be parsed once looking for types variables and functions etc, and then again to actually compile code. Unfortunately C++ is an ancient language in comparison, and a lot of its problems are issues inherited from C. Needing forward declarations may be fixed with the C++ "modules" proposal being worked on at the moment for a future version of C++ (possibly C++17).

Re: templates:
1: You don't need them:
Code: [Select]
void clear_box(int inputarr[5][5])
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; i++)
{
inputarr[i][j] = 0;
}
}
}

Works perfectly.

2:
When you wrote this:
Code: [Select]
template <int height, int width>
void copy_array(int from[][height], int to[][width])
you probably meant:
Code: [Select]
template <int height, int width>
void copy_array(int from[height][width], int to[height][width])

3: When you use "<" in a for loop's condition, it excludes its end value.
So when you wrote this:
Code: [Select]
for (int i = 0; i < height - 1; i++)you are looping from 0 to up to and not including 4 (height - 1 == 4). You either mean "< height" or "<= height - 1"
« Last Edit: January 21, 2015, 04:08:11 pm by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6904 on: January 21, 2015, 04:00:40 pm »

No it includes 4. 4 is the last run because 4 < 5 resolves. 5< 5 does not resolve true and therefore is a good way to iterate over an array of length 5 (0 - 4).

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6905 on: January 21, 2015, 04:03:48 pm »

Did you miss the "- 1" in his code?
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6906 on: January 21, 2015, 04:05:30 pm »

The original source code reads:

for (int i = 0; i < height - 1; i++)

If "height" is 5, then this will loop 0-3, which is clearly a mistake.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6907 on: January 21, 2015, 04:06:28 pm »

Wait. I'm confused.

for (int i = 0; i < height - 1; i++)

If "height" is 5, then this will loop 0-3

This is what I'm getting. You'd want

for (int i = 0; i <= height - 1 ; i++)

which is just more keystrokes.

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6908 on: January 21, 2015, 04:07:18 pm »

Or "for (int i = 0; i < height ; i++)" (without the "- 1"). Like I said.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6909 on: January 21, 2015, 04:08:43 pm »

Wait. I'm confused.

for (int i = 0; i < height - 1; i++)

If "height" is 5, then this will loop 0-3

This is what I'm getting. You'd want

for (int i = 0; i <= height - 1 ; i++)

which is just more keystrokes.

Just take the -1 off and have it "< height" would fix it. I don't think you're processing what we're discussing, which is someone else's faulty code.

miauw62 also has lines that loop from "0" to "<4" for a 5-dimensional array. I think he's systematically missing the last iteration of every loop.
« Last Edit: January 21, 2015, 04:10:50 pm by Reelya »
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6910 on: January 21, 2015, 04:10:48 pm »

Yes that is true D: I'm very confused and will wait patiently until next discussion.

DreamThorn

  • Bay Watcher
  • Seer of Void
    • View Profile
    • My game dev hobby blog (updates almost never)
Re: if self.isCoder(): post() #Programming Thread
« Reply #6911 on: January 28, 2015, 05:41:47 am »

@Pufferfish:
Step-by-step explanation:

X x[h];
This creates an array with h elements, indexed from 0 to h-1.

for (int i = 0; i < h-1; i++) {};
This loops from 0 to h-2, because when (i == h-1), the (i < h-1) test fails and it exits from the loop immediately.

If you want to include all the elements, it should be (i < h).

@EveryoneElse:
GitHub mystifies me.  I forked a project, but now I'm stuck.
1. Which is the right way to get the code to my machine so that I can make changes and send them back to my fork?
2. The original project has had other changes made in the meantime, so how do I get my fork up-to-date?

I'm sure I'll have more questions later, when I'm less mystified.  :-\
Logged
This is what happens when we randomly murder people.

You get attacked by a Yandere triangle monster.

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6912 on: January 28, 2015, 05:59:51 am »

1. GitHub has a client now which is the easiest way to download/upload from a github repository. Otherwise you need to learn how to operate Git.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6913 on: January 28, 2015, 06:09:48 am »

1. Git's Windows client is terribad. I recommend using something like Git Extensions, which has various options and not everything is a bloody square.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

DreamThorn

  • Bay Watcher
  • Seer of Void
    • View Profile
    • My game dev hobby blog (updates almost never)
Re: if self.isCoder(): post() #Programming Thread
« Reply #6914 on: January 28, 2015, 07:15:53 am »

Thanks, I'll take a look.
Logged
This is what happens when we randomly murder people.

You get attacked by a Yandere triangle monster.
Pages: 1 ... 459 460 [461] 462 463 ... 796