Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 503 504 [505] 506 507 ... 796

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

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7560 on: July 02, 2015, 03:27:04 pm »

That function doesn't return two ints. It returns just one int. (row, col) does not automagically create something that holds two ints, nor does it change the return type of the function.

If you want to return two ints use pair<int, int>, return pair<int, int>(row, col), and pair<int, int> WHATEVER = foo. You can get stuff out of a pair with .first and .second.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7561 on: July 02, 2015, 07:07:30 pm »

That function doesn't return two ints. It returns just one int. (row, col) does not automagically create something that holds two ints, nor does it change the return type of the function.

If you want to return two ints use pair<int, int>, return pair<int, int>(row, col), and pair<int, int> WHATEVER = foo. You can get stuff out of a pair with .first and .second.
Or use a struct.
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7562 on: July 02, 2015, 09:22:53 pm »

the alternative is to pass by reference or pass by pointer, then modify the sent values. Pass by pointer has one advantage - the calling code needs to put an & before the variable name, which lets you know it's being modified. Normally you should not modify sent parameters.

also Spehss, "const" values cannot be set to a value returned from a function. "const" means "constant" as in "not variable", so they can only be given a value when you declare them.
« Last Edit: July 02, 2015, 09:26:44 pm by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7563 on: July 02, 2015, 09:28:07 pm »

also Spehss, "const" values cannot be set to a value returned from a function. "const" means "constant" as in "not variable".
So I couldn't just do

Code: [Select]
const int foo = bar();
at the start of main()?

I could just make them normal ints then, I only figured I'd use const because it wouldn't be necessary to change them once defined.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7564 on: July 02, 2015, 09:32:49 pm »

In the new C++ standard I think you can add some kind of type decorator to functions to allow them to do that.  Or... something.  I think the function effectively has to end up as some kind of expression that the compiler can inline at the initialization point of the variable.  The new C++ standard is so different from what I'm used to that it might as well be its own language though, so I'm not sure what the details are.

In general though, no, you can't do that.
Logged
Through pain, I find wisdom.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7565 on: July 03, 2015, 04:36:35 am »

The real advantage of const is that they are set at compile-time rather than runtime. That means that values are hard-wired into your instruction code rather than telling the machine to look up a value somewhere else, as a variable would.

The other main advantage of const is to make function parameters as "const &" - const references.

A reference just tells the function where to find the variable, it just passes the existing variable's memory address, and avoids the default behaviour (pass-by-value) which is to (1) look up the variable, (2) allocate memory for a new variable of the same size (3) call the copy constructor function for the new variable and copy from the old variable, (4) pass the address of the new variavble to your function. So with pass by value, you're calling multiple other functions to pass each parameter to your function. Which is as slow as it sounds.

So, passing by reference whenever possible cuts some overhead down. The danger is that you can then edit a value inside the function and break the calling code unexpectedly. This is where defaulting to "const &" paramters helps. They're passed by reference, but the compile spits and error if you try and change them.

Note that if you pass a const value to a function that also takes const, then it doesn't look up anything, the "hardwired" const value itself is put into the code where you called it, so it is very fast, and explains why you can't pass a non-const variable into a const variable, but you can do the opposite - pass a const value to a non-const parameter - because it copies it into the new variable. Note for "const &" it's the reference that is const, not the variable itself, so you can actually pass non-const values into a "const &" variable.
« Last Edit: July 03, 2015, 04:45:37 am by Reelya »
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7566 on: July 03, 2015, 02:35:40 pm »

Woo, I converted my big ancient lab management ruby 1.8.6 rails app into a big exactly-the-same ruby  2.2.2 Sinatra app.

I sure hope nothing explodes.   :P  :P  :-X  :P
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Sappho

  • Bay Watcher
  • AKA Aira; Legendary Female Gamer
    • View Profile
    • Aira Plays Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #7567 on: July 13, 2015, 02:34:12 am »

Hello programming friends! I'm writing an article for one of the magazines I work for on programming, and since I'm really not a programmer and have only the most basic understanding of this stuff, I'm hoping one or two of you guys will be willing to answer some questions. I don't want to hijack the thread though - is there anyone who'd be willing to answer a few questions via PM or email (and possibly even have a line or two published in the magazine)?

We may also want to include an interview with a programmer. I think my editor prefers to go with a Czech person, but she may be open to others, if any of you is interested in that. We'd need a text interview (probably by email) and at least one or two good pictures (quality is important - our graphic designers are very picky about having high-quality images). Any volunteers, again, send me a PM.

Thanks guys!

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7568 on: July 13, 2015, 02:48:39 am »

I'd love to help but there's no way I'm good enough at programming to be worth interviewing.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7569 on: July 13, 2015, 03:06:43 am »

Hello programming friends! I'm writing an article for one of the magazines I work for on programming, and since I'm really not a programmer and have only the most basic understanding of this stuff, I'm hoping one or two of you guys will be willing to answer some questions. I don't want to hijack the thread though - is there anyone who'd be willing to answer a few questions via PM or email (and possibly even have a line or two published in the magazine)?

We may also want to include an interview with a programmer. I think my editor prefers to go with a Czech person, but she may be open to others, if any of you is interested in that. We'd need a text interview (probably by email) and at least one or two good pictures (quality is important - our graphic designers are very picky about having high-quality images). Any volunteers, again, send me a PM.

Thanks guys!
I'm up to answer any questions you have, but I'm not sure about an interview. You are probably best off interviewing someone with more professional credtentials than me I guess.

My credentials are a computer science degree, dabbling in open source and amateur coding projects / homebrew games, some published game programming work for a studio here in Melbourne Australia (on a Game Boy Advance game, this was a while ago) and currently studying a second degree, Bachelor of Games Development. So I can certainly answer most general programming questions, or steer you to where you can get the answers you need.
« Last Edit: July 13, 2015, 03:09:15 am by Reelya »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7570 on: July 13, 2015, 03:10:09 am »

Just out of interest (seeing as I am not in any way qualified to be interviewed on the topic), what kind of questions are you wanting to ask?
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.

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #7571 on: July 13, 2015, 03:10:47 am »

You are probably best off interviewing someone with more professional credtentials than me I guess.

computer science degree, dabbling in open source and amateur coding projects / homebrew games, some published game programming work and currently studying a second degree, Bachelor of Games Development

Hate to break it to you Reelya, but you've got pretty good professional cred. And good actual cred, having read most of your posts to this thread.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

Sappho

  • Bay Watcher
  • AKA Aira; Legendary Female Gamer
    • View Profile
    • Aira Plays Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #7572 on: July 13, 2015, 04:21:15 am »

Looks like we've found 2 possible local candidates for an interview, so that's no longer necessary. This article is very basic. It's for 12-15-year-old Czech learners of English, and they are beginners at the language, so there's no room for real depth. I'm basically just writing an overview of what programming is, things it can be used for, and where the readers can get started learning it. I only have room for maybe 600-700 words total (maybe a bit more if we include a short interview), so there's no room to get too deep into it, unfortunately.

My outline is basically an intro explaining that programming is used to write games, software, web sites, and even things like creating art and doing math. Then there's a section saying anyone can do it - boy, girl, young, old, doesn't matter. Then a little box pointing out that English is important if you want to code, because most programming languages are based on English (and most tutorials and such are in English). Next is a box listing resources for how to get started - again, I'm short on space, so I'm putting code academy, the book "python for kids", and the game "lightbox". I've written all this already. Now I'm working on a short section on what you can do with code, with just a sentence or two on games, applications, web sites, and an example of art made with code (secrettechnology.com).

But it would be cool to include a sentence or two from a few different "real-life" programmers, just to inspire the readers. I'm especially interested in inspiring *female* readers - any female programmers are especially invited to write something about how it's not just for boys, etc. Or a sentence or two about how/why you got started, what your favorite project was... Basically, if you've got the chance to write 1-2 sentences to young potential programmers, what would you want to tell them? I'll work in as many lines from you guys as possible. And when it's done, anyone who helped will get a PDF copy of the article. :)

EDIT: Oh, holy crap, I just discovered codecombat.com ... This is the COOLEST code-teaching thing I've ever seen. This is going to replace Lightbox in the article, clearly, and also I'm addicted already.
« Last Edit: July 13, 2015, 05:18:46 am by Sappho »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7573 on: July 13, 2015, 05:37:38 am »

I thought about maybe creating a script for text-based dialog trees to put on the Unity Asset Store. Maybe $5 at the most; nothing I write is going to compare to the items at the top of the price range, seeing as I can't even wrap my head around writing a custom editor for it.

Anyways, there's a class in the system called dialogOptions, which has a string to put on the UI button, a string referring to the name of the dialogState it links to, and an actual dialogState variable which is filled in at runtime.

For the longest time, it looked like the string was getting nulled somewhere along the line. It wouldn't show up in Debug.Log at any point in execution, and any lines referring to it spat out NullReferenceExceptions. I ran around in circles for hours trying to find the problem, combing up and down Google results and various forums. Near the end, I even considered submitting a bug report for Unity.

It turns out that while I included a string argument in the constructor, at no point in the definition do I ever actually assign a value to the string in dialogOptions. I'm an idiot, I probably should not charge money for anything I write.



EDIT: Also, I commented out some code that removed all listeners before adding new ones, then forgot that I did this. Cue another ten minutes of Googling while I wondered why the number of listeners on the button grew exponentially with every click. :(
« Last Edit: July 14, 2015, 02:28:28 am by itisnotlogical »
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7574 on: July 16, 2015, 07:29:59 pm »

Is there any general way to figure out where on a web page an element will appear from the source code, given that the size of the browser window is known in advance? Alternatively, and actually more conveniently, to figure out from an element's position on the page where to look for it in the source code? What I'm trying to do is automate a process that tries to identify and click on certain buttons; I'll be doing some stuff later to try and teach it how to identify what a button is from screenshots of a given website, and which ones are worthwhile, but before I can do that I need to do this.

Since a lot of buttons use images instead of text, and I can't rely on web developers using informative filenames for them, I'm trying to extract information from the appearance of the site as well as its source. It's easy enough to tell a browser to do something to an element of a web page if I know its id or name or something like that, but what I'm using (Selenium) doesn't seem to have an efficient way to do this with coordinates - probably because it's aimed at testing, where you'd have that information and it'd be a lot more reliable, and so I'm sort of abusing the functionality. I just haven't found anything better-suited. Anyway, since I can only interact with the website through a tool that reads its source, I need some way of getting information from some analysis of its appearance into being in terms of its elements.

EDIT: Seems there is. I just needed better Google-Fu. Now I just gotta figure out how to make it work for me.

EDIT: And even basic reading on Selenium shows other ways of doing it. Damn, I suck.
« Last Edit: July 16, 2015, 07:55:12 pm by Bauglir »
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.
Pages: 1 ... 503 504 [505] 506 507 ... 796