Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411273 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 03:04:38 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 4 5 [6] 7 8 ... 69
Print
Author Topic: General thread for quick questions  (Read 132613 times)
Sik
Level 10
*****


View Profile WWW
« Reply #100 on: July 28, 2015, 06:16:01 AM »

The idea is that you return error values so you can check when an error happens (you can log and such too, of course), but your API tolerates when the code ignores the error values and attempts to do something coherent (unless there's absolutely no way out, mind you).

EDIT: your API does something coherent, I mean (・<・)
« Last Edit: July 28, 2015, 06:26:18 AM by Sik » Logged
eliasfrost
Level 0
***



View Profile
« Reply #101 on: July 28, 2015, 07:20:31 AM »

I got a book for Java (per recommendation from another thread) and I saw an example where they use a while loop that looks like this:

while(true)
{
  //do stuff
  if (condition is met)
    break;
}

I haven't seen this before so I looked it up and some people say it's bad practice because it's not particularly clear what you're testing (which I agree with, I always use flags.. Mostly because I didn't know another way to do it). I was suprised to learn this as they use while(true) in the book. Any opinions on this? Why would I use while(true) in place of something that is more specific like while(size < threshold)?
« Last Edit: July 28, 2015, 07:28:00 AM by eliasfrost » Logged

Dacke
Level 10
*****



View Profile
« Reply #102 on: July 28, 2015, 07:27:28 AM »

It's pretty inelegant. But sometimes you want to break in the middle of the loop and only in the middle of the loop. So then you can do something like that.

Code:
while (true) {
   //do stuff
   if (something) {
      break;
   }
   //do more stuff
}
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
eliasfrost
Level 0
***



View Profile
« Reply #103 on: July 28, 2015, 09:19:39 AM »

Thank you Dacke. Smiley
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #104 on: July 28, 2015, 09:20:39 AM »

I would love to see an example of such a case where it is truly the best way to go.
Logged

Sqorgar
Level 0
**


View Profile
« Reply #105 on: July 28, 2015, 10:37:14 AM »

I got a book for Java (per recommendation from another thread) and I saw an example where they use a while loop that looks like this:

while(true)
{
  //do stuff
  if (condition is met)
    break;
}

I haven't seen this before so I looked it up and some people say it's bad practice because it's not particularly clear what you're testing (which I agree with, I always use flags.. Mostly because I didn't know another way to do it). I was suprised to learn this as they use while(true) in the book. Any opinions on this? Why would I use while(true) in place of something that is more specific like while(size < threshold)?

Sometimes, the condition needed to break a loop isn't known at the beginning of the loop (or can't be accessed, like testing inner variables), or a loop can be broken in multiple places for multiple reasons and the order they are checked is important. Or, as mentioned, sometimes you want to make sure the beginning of a loop executes and want to break the loop in the middle.

There's actually a lot of reasons to do this, and I use it all the time. I do a lot of procedural generation and it is not always obvious how many iterations are needed, or what the success conditions will end up being. There are conditions that are only valid some of the time, and some conditions depend on variables that change frequently depending on what happened in the loop. There might be a half dozen different breaks and continues in a single loop. While you CAN model this all with a single master condition (like a flag), it would actually be an exception and probably more complicated to implement than a simple while(true).
Logged
@Alex@
Level 0
***


View Profile
« Reply #106 on: July 29, 2015, 04:16:33 AM »

I've been looking for general purpose algorithms to implement in GameMaker to just improve my skills in general. However I've struggled finding interesting ones to take a run at. Any suggestions? For reference recently I've done things like Bresham's line algorithm, flood fill and colour comparisons.

Though I'll be implementing them in GameMaker, I am actually looking for resources that don't tailor themselves toward the engine.
Logged
eliasfrost
Level 0
***



View Profile
« Reply #107 on: July 29, 2015, 04:22:11 AM »

Sometimes, the condition needed to break a loop isn't known at the beginning of the loop (or can't be accessed, like testing inner variables), or a loop can be broken in multiple places for multiple reasons and the order they are checked is important. Or, as mentioned, sometimes you want to make sure the beginning of a loop executes and want to break the loop in the middle.

There's actually a lot of reasons to do this, and I use it all the time. I do a lot of procedural generation and it is not always obvious how many iterations are needed, or what the success conditions will end up being. There are conditions that are only valid some of the time, and some conditions depend on variables that change frequently depending on what happened in the loop. There might be a half dozen different breaks and continues in a single loop. While you CAN model this all with a single master condition (like a flag), it would actually be an exception and probably more complicated to implement than a simple while(true).


That's interesting, thanks Sqorgar Smiley
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #108 on: July 29, 2015, 04:56:51 AM »

I've been looking for general purpose algorithms to implement in GameMaker to just improve my skills in general. However I've struggled finding interesting ones to take a run at. Any suggestions? For reference recently I've done things like Bresham's line algorithm, flood fill and colour comparisons.

Though I'll be implementing them in GameMaker, I am actually looking for resources that don't tailor themselves toward the engine.
http://forums.tigsource.com/index.php?topic=49173.0
This might interest you?
Logged

@Alex@
Level 0
***


View Profile
« Reply #109 on: July 29, 2015, 05:27:56 AM »

Easing quite interesting, I've got a background in PID controllers. Thanks for the link, will watch the related video to see if its something I want to pursue.
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #110 on: July 30, 2015, 06:12:01 AM »

Ok ok ok ok ok guys I'm obviously very wrong but hear me out okay?

In c++, why does no one simply put their whole class definitions in a single header file instead of doing the retarded thing of having a .h and a .cpp for every single class? I want to know why it is common practice to be so overly complicated for no reason.
Logged

oahda
Level 10
*****



View Profile
« Reply #111 on: July 30, 2015, 06:45:22 AM »

For one, you don't have to include everything in the header, which can slow down compile time, and more problematically create circular dependencies that mean you can't compile at all.

Even disregarding that, tho, I prefer it this way, because this way I can use the header file as a table of contents for the much more messy source file.

Also this means you can compile libraries and stuff to a single library file of some sort and a user will only need your headers and won't need to recompile any implementation from your library, which might require further dependencies that you can skip if you're just linking to the library file that has already been linked against them when created.
Logged

Sqorgar
Level 0
**


View Profile
« Reply #112 on: July 30, 2015, 12:24:25 PM »

Ok ok ok ok ok guys I'm obviously very wrong but hear me out okay?

In c++, why does no one simply put their whole class definitions in a single header file instead of doing the retarded thing of having a .h and a .cpp for every single class? I want to know why it is common practice to be so overly complicated for no reason.

It's a holdover from the way C did it, as C++ is basically a thin layer built on top of a C compiler. The long and short of it is, individual .c files are compiled separately into .o files and then linked together at the final step. In order to compile a file which contains references to other modules, the compiler basically just needs to know that a variable or function exists, and in what format. Then when the independently compiled modules are linked together, it tries to find the code that goes with each reference. When these mismatch, you get a linking error.

Short version: the header files includes public information for the linker to allow large programs made up of discrete modules to be compiled in increments.

Ultimately, you are only supposed to export the header information that is shared with other modules, so you shouldn't be putting private variables or functions in the header. If you do make internal data public, you end up creating dependencies which can be quite annoying. When I worked in the game industry, our project exposed all sorts of private information, and had to recompile the ENTIRE project each build, which took several minutes. I spent a week going through and hiding private information and using pointers instead of direct references and managed to remove all those dependencies, reducing compile time to seconds. No one thanked me Sad

Languages like Java don't have explicit header files, and instead compiles that information automatically during a build. Java doesn't compile to machine language, so the .class files are similar to the unlinked/compiled .o files a C compiler builds. It's just that the virtual machine runtime has a built-in, dynamic linker. So it's doing the same things, largely in the same way, but requires access to all the .class files you will use during compilation whereas C/C++ does not.

Also, I should point out that you don't need a .h for every .cpp. Personally, I put multiple class definitions in a single header file (in Objective-C). Too many header files are unwieldy, so I use a single header file to represent the public interface to an entire module.
Logged
oahda
Level 10
*****



View Profile
« Reply #113 on: July 30, 2015, 12:28:08 PM »

Huh? How do you declare private members in the source file? C++ doesn't have partial classes like C#...

What am I misunderstanding?
Logged

Sqorgar
Level 0
**


View Profile
« Reply #114 on: July 30, 2015, 12:50:45 PM »

Huh? How do you declare private members in the source file? C++ doesn't have partial classes like C#...

What am I misunderstanding?
Sorry, I was in Objective-C mode. There are ways to hide private data in a C++ header though. If compilation is your concern, use pointers to structs/classes instead of the structs/classes directly, since C++ need class definitions to use structs/classes, but not pointers to that them.

If you want to hide the data itself, you can forward declare an inner struct/class that you then define in the implementation file. That struct holds the private data, so while the public interface knows that struct exists, only the class file knows what is in it. There's a name for this pattern, but I can't remember it right now. It might be pimple or something.

There was this really good book I read a long time ago about large scale C++ project management, and about half of it was just really creative ways to hide private data.
Logged
oahda
Level 10
*****



View Profile
« Reply #115 on: July 30, 2015, 12:57:18 PM »

Oh, right. I actually do some of that.
Logged

indie11
Level 2
**


View Profile
« Reply #116 on: July 30, 2015, 01:24:52 PM »

a little off topic but.. What language should I learn to scrap data from different websites? Python? Or is there any other language with bunch of useful libraries ?
Logged

Sqorgar
Level 0
**


View Profile
« Reply #117 on: July 30, 2015, 04:48:44 PM »

a little off topic but.. What language should I learn to scrap data from different websites? Python? Or is there any other language with bunch of useful libraries ?
According to Google, there are several scraping APIs out there, so I'd look into the APIs and then pick the language that went with the best one. Looks like Python and Ruby are the big ones.
Logged
Cheesegrater
Level 1
*



View Profile
« Reply #118 on: July 30, 2015, 05:38:18 PM »

Anything that has a good regular expression library will be fine. Perl is the traditional choice for that kind of thing, but Python and/or Ruby are probably more approachable these days.
Logged
Mightymcc21
Level 0
*


View Profile
« Reply #119 on: August 02, 2015, 04:31:36 PM »

Hey, I have a question about prefabs in unity.

I currently have an enemy prefab and I'm trying to reference it and its attached code (More specifically a certain variable). I figured that I could just call the code component normally with:

enemycode = GameObject.FindGameObjectWithTag("enemy").GetComponent<EnemyCode> ();

However, when I do this it only affects a single instance of the prefab. (I have between 1 - 3 instances at any given time). Is there a special way to do this so that I can affect all the instances?
Logged
Pages: 1 ... 4 5 [6] 7 8 ... 69
Print
Jump to:  

Theme orange-lt created by panic