• What are you working on?
    5,004 replies, posted
[QUOTE=mojangsta;49474613]After a lot of resistance I finally gave in to using Lua for a new project, due to the appeal of [url=https://love2d.org]LÖVE[/url]. Christ though, Lua lacks so many things like binary operators and goto's and it really bothers me. [editline]7th January 2016[/editline] [i]That[/i] is the coolest thing I've read in weeks.[/QUOTE] [quote] Lua 5.3 was released on 12 Jan 2015. Its main new features are integers, bitwise operators, a basic utf-8 library, and support for both 64-bit and 32-bit platforms. [/quote] lua is pretty cool
[QUOTE=MatheusMCardoso;49470700]added deltatime to loop callback and scripts can now be reloaded on the fly [media]https://www.youtube.com/watch?v=IT62c_4t8RE[/media][/QUOTE] Instead of spamming the DT why not use something like this? [url]https://github.com/Mechazawa/Love-Debug-Graph[/url] [code] function love.load() local debugGraph = require 'debugGraph' fpsGraph = debugGraph:new('fps', 0, 0) end function love.update(dt) -- Update the graph fpsGraph:update(dt) end function love.draw() -- Draw graph fpsGraph:draw() end[/code]
[QUOTE=Map in a box;49474861] The only thing LuaJIT needs is continue/bitwise operators and I'd switch to using it fulltime.[/QUOTE] I added continue to LuaJIT some time ago as part of a module that would replace the Lua implementation in Garry's Mod. It's not really useful for that anymore, but it's still LuaJIT with a continue keyword. There's no bitwise operators though (but who needs them when you have a perfectly usable bit library). [url]https://dl.dropboxusercontent.com/u/20789739/gmod_luajit.rar[/url] Just remove the gmod bits and you should be good to go.
[QUOTE=Mega1mpact;49475124]Instead of spamming the DT why not use something like this? [url]https://github.com/Mechazawa/Love-Debug-Graph[/url] [code] function love.load() local debugGraph = require 'debugGraph' fpsGraph = debugGraph:new('fps', 0, 0) end function love.update(dt) -- Update the graph fpsGraph:update(dt) end function love.draw() -- Draw graph fpsGraph:draw() end[/code][/QUOTE] I would have to implement those functions and the idea is you only have access to changing the number and color of cells to make minimalistic games like snake and game of life. Maybe i'll do it from the C++ side and let the script toggle it.
[QUOTE=roastchicken;49471267]Has anyone here used Torque3D, and if so how was your experience with it?[/QUOTE] it's pretty good the editor is superb the scripting language is close to awful though and if i remember correctly, making custom shaders is a pain in the ass
I found a package on the Unity Asset Store that adds every imaginable flavor of inverse kinematics, like foot grounding, aiming, grabbing things, etc. It basically does everything that Unity's built-in DogShitâ„¢ IK [I]should[/I] do, but better and with more features. I am going to have [I]so much fun[/I] using this. The first thing I'm going to do is make Glass actually grip the steering wheel in his Caprice!
Hey guys! New to Facepunch, just wanted to introduce myself. Aspiring coder here, its safe to say I know around 6 languages. Hoping to learn more. Anyway, Here's what I coded in C++ after only doing it a day. Learning C++ for UE4 game development and hope to make some pretty good video games. Someone said I have a really weird unorganized coding style. Is it all that bad? [CODE] #include <iostream> #include <stdlib.h> #include <string> #include <cstdlib> using namespace std; int guess; int tries1; int answer = rand() % 101; bool playAgain; int wouldYouLikeToPlayAgain(); void repeat() { if (guess < answer){ cout << "The answer is greater then what you guessed!" << endl; } else if (guess > answer){ cout << "The guess is less then what you guessed!" << endl; } } int main() { cout << "Guess a number I'm thinking off thats between 100 and 1! ( They can only be integers )" << endl; cin >> guess; if( guess == answer ){ cout << "You guessed the right number!" << endl; } repeat(); wouldYouLikeToPlayAgain(); } int wouldYouLikeToPlayAgain(){ playAgain = false; int playA; do{ cout << "Would you like to play again? "; cout << " 1 / yes 2 / no" << endl; } while ( playAgain = false ); cin >> playA; if ( playA == 1 ){ main(); } else if ( playA == 2 ){ return 0; } } [/CODE] If coding style is a little weird it might be because I'm coding in Qt on a chromebook lmao
[QUOTE=Verideth;49475611]Hey guys! New to Facepunch, just wanted to introduce myself. Aspiring coder here, its safe to say I know around 6 languages. Hoping to learn more. Anyway, Here's what I coded in C++ after only doing it a day. Learning C++ for UE4 game development and hope to make some pretty good video games. Someone said I have a really weird unorganized coding style. Is it all that bad? [CODE] #include <iostream> #include <stdlib.h> #include <string> #include <cstdlib> using namespace std; int guess; int tries1; int answer = rand() % 101; bool playAgain; int wouldYouLikeToPlayAgain(); void repeat() { if (guess < answer){ cout << "The answer is greater then what you guessed!" << endl; } else if (guess > answer){ cout << "The guess is less then what you guessed!" << endl; } } int main() { cout << "Guess a number I'm thinking off thats between 100 and 1! ( They can only be integers )" << endl; cin >> guess; if( guess == answer ){ cout << "You guessed the right number!" << endl; } repeat(); wouldYouLikeToPlayAgain(); } int wouldYouLikeToPlayAgain(){ playAgain = false; int playA; do{ cout << "Would you like to play again? "; cout << " 1 / yes 2 / no" << endl; } while ( playAgain = false ); cin >> playA; if ( playA == 1 ){ main(); } else if ( playA == 2 ){ return 0; } } [/CODE][/QUOTE] It's bad to call main() manually, and because you're technically using main() as a recursive function (main() calls a function that calls main()), so you'll end up with a stack overflow at some point. And since you're not setting a seed for rand(), the sequence of answers is always going to be the same. And your "do {} while(playAgain = false)" is incorrect, you should use two equal signs. Right now you are assigning false to playAgain, so the whileloop will run once, then stop executing, because the statement is always false.
[QUOTE=Cyberuben;49475624]It's bad to call main() manually, and because you're technically using main() as a recursive function (main() calls a function that calls main()), so you'll end up with a stack overflow at some point. And since you're not setting a seed for rand(), the sequence of answers is always going to be the same.[/QUOTE] Hm, thanks for the response. So maybe make another function and put the contents of that inside that function?
[QUOTE=Verideth;49475627]Hm, thanks for the response. So maybe make another function and put the contents of that inside that function?[/QUOTE] [code] function main() { bool playing = true; while(playing) { // your game logic here // and in case someone doesn't want to play again: playing = false; // this will cause the while loop to stop iterating and result in main() returning 0 thus exiting the program } return 0; [/code] Also check my edit on my previous post
[QUOTE=Cyberuben;49475624] And since you're not setting a seed for rand(), the sequence of answers is always going to be the same.[/QUOTE] Just a question, on cpluspus.com, the example for rand() is [CODE]v1 = rand() % 100; // v1 in the range 0 to 99[/CODE] So, I thought it would just incude every number < what is is? [editline]7th January 2016[/editline] [QUOTE=Cyberuben;49475624] And your "do {} while(playAgain = false)" is incorrect, you should use two equal signs. Right now you are assigning false to playAgain, so the whileloop will run once, then stop executing, because the statement is always false.[/QUOTE] Haha silly mistake on my side. I know you have to do ==
[QUOTE=Verideth;49475635]Just a question, on cpluspus.com, the example for rand() is [CODE]v1 = rand() % 100; // v1 in the range 0 to 99[/CODE] So, I thought it would just incude every number < what is is?[/QUOTE] That is not the point. Seeds are there to generate unique random numbers (pseudo random, but not relevant right now). If you don't set a seed, and you run your program, a possible outcome of calling rand() 10 times modulo 100, could result in the following numbers: 20, 8, 48, 1, 90, 58, 32, 41, 88, 39 The 2nd time you run your program (stop it, start it again), it'll have the same outcome, because the seed is the same (not set to anything different). Use srand(time(NULL)) (just an example) to set a random seed. Running this program will generate the same output every time you run it: [url]http://cpp.sh/9wweh[/url] This won't: [url]http://cpp.sh/6o3e[/url]
[QUOTE=Cyberuben;49475646]That is not the point. Seeds are there to generate unique random numbers (pseudo random, but not relevant right now). If you don't set a seed, and you run your program, a possible outcome of calling rand() 10 times modulo 100, could result in the following numbers: 20, 8, 48, 1, 90, 58, 32, 41, 88, 39 The 2nd time you run your program (stop it, start it again), it'll have the same outcome, because the seed is the same (not set to anything different). Use srand(time(NULL)) (just an example) to set a random seed. Running this program will generate the same output every time you run it: [url]http://cpp.sh/9wweh[/url] This won't: [url]http://cpp.sh/6o3e[/url][/QUOTE] Ohhhhhh okay I get it now haha, thanks so much. I'll go back and fix it.
[URL="https://youtu.be/LDPMpc-ENqY"]Don't use rand()[/URL]
[QUOTE=Anven11;49475696][URL="https://youtu.be/LDPMpc-ENqY"]Don't use rand()[/URL][/QUOTE] yeah except that this isn't cryptography or anything where it matters, it's just a game [editline]7th January 2016[/editline] [QUOTE=Verideth;49475611]Hey guys! New to Facepunch, just wanted to introduce myself. Aspiring coder here, its safe to say I know around 6 languages. Hoping to learn more. Anyway, Here's what I coded in C++ after only doing it a day. Learning C++ for UE4 game development and hope to make some pretty good video games. Someone said I have a really weird unorganized coding style. Is it all that bad? [CODE] #include <iostream> #include <stdlib.h> #include <string> #include <cstdlib> using namespace std; int guess; int tries1; int answer = rand() % 101; bool playAgain; int wouldYouLikeToPlayAgain(); void repeat() { if (guess < answer){ cout << "The answer is greater then what you guessed!" << endl; } else if (guess > answer){ cout << "The guess is less then what you guessed!" << endl; } } int main() { cout << "Guess a number I'm thinking off thats between 100 and 1! ( They can only be integers )" << endl; cin >> guess; if( guess == answer ){ cout << "You guessed the right number!" << endl; } repeat(); wouldYouLikeToPlayAgain(); } int wouldYouLikeToPlayAgain(){ playAgain = false; int playA; do{ cout << "Would you like to play again? "; cout << " 1 / yes 2 / no" << endl; } while ( playAgain = false ); cin >> playA; if ( playA == 1 ){ main(); } else if ( playA == 2 ){ return 0; } } [/CODE] If coding style is a little weird it might be because I'm coding in Qt on a chromebook lmao[/QUOTE] i guess that the problem with this is that you're mixing c and c++ code together which looks bad i'd suggest to only use stuff from modern c++ (c++11 and up) and not touch the c standard library at all although if you're only going to use c++ in unreal then its probably fine i dont know if unreal even uses modern c++ at least the source engine uses some kind of ancient form of c++ and their own standard library which is pretty much c so the code you write ends up looking like the code you wrote above [editline]7th January 2016[/editline] also in the beginning you're doing [code]if (guess < answer){[/code] but then later on you're doing [code]if ( playA == 1 ){[/code] whichever is fine but you need to be consistent
[QUOTE=Verideth;49475611] Aspiring coder here, its safe to say I know around 6 languages. Hoping to learn more.[/QUOTE] I would be careful about saying you know a language Theres much more to a language than a few simple programs can touch on I wrote some stuff in a bunch of languages but i would never say that i know those langs just because of that Its almost like saying you know chinese when all you know are a handful of conversational phrases in mandarin
[QUOTE=DarKSunrise;49475791]yeah except that this isn't cryptography or anything where it matters, it's just a game[/QUOTE] It's still bad practice and less readable.
[QUOTE=Verideth;49475611]Hey guys! New to Facepunch, just wanted to introduce myself. Aspiring coder here, its safe to say I know around 6 languages. Hoping to learn more. Anyway, Here's what I coded in C++ after only doing it a day. Learning C++ for UE4 game development and hope to make some pretty good video games. Someone said I have a really weird unorganized coding style. Is it all that bad? [CODE] #include <iostream> #include <stdlib.h> #include <string> #include <cstdlib> using namespace std; int guess; int tries1; int answer = rand() % 101; bool playAgain; int wouldYouLikeToPlayAgain(); void repeat() { if (guess < answer){ cout << "The answer is greater then what you guessed!" << endl; } else if (guess > answer){ cout << "The guess is less then what you guessed!" << endl; } } int main() { cout << "Guess a number I'm thinking off thats between 100 and 1! ( They can only be integers )" << endl; cin >> guess; if( guess == answer ){ cout << "You guessed the right number!" << endl; } repeat(); wouldYouLikeToPlayAgain(); } int wouldYouLikeToPlayAgain(){ playAgain = false; int playA; do{ cout << "Would you like to play again? "; cout << " 1 / yes 2 / no" << endl; } while ( playAgain = false ); cin >> playA; if ( playA == 1 ){ main(); } else if ( playA == 2 ){ return 0; } } [/CODE] If coding style is a little weird it might be because I'm coding in Qt on a chromebook lmao[/QUOTE] try to get into the habit of not using global variables when you could use local variables instead - while it doesn't matter in a small project, if you're looking to make games and you're using global variables it'll pollute the namespace and become an absolute nightmare. Global variables are generally considered bad practice. For example, declare your guess integer inside main, and pass it into repeat to run your comparison, instead of accessing it globally in both functions. Also, generally, don't call main recursively. [editline]8th January 2016[/editline] Also your main function doesn't return a value even though its defined as an int. The program probably isn't affected by that but you should really make it return some sort of int. The same goes for wouldYouLikeToPlayAgain() - if the user types in unknown input there's no value returned which might cause a runtime error - because you've used an if, else if with no else.
My first programming book purchase! Ordered on Tuesday, took 2 days to arrive in the amazon locker at my uni. I am so happy with it. [thumb]http://richardbamford.io/dmp/oglsuperbible.jpg[/thumb] [url]http://www.amazon.co.uk/OpenGL-Superbible-Comprehensive-Tutorial-Reference/dp/0672337479/ref=sr_1_1?ie=UTF8&qid=1452178682&sr=8-1&keywords=superbible[/url]
[QUOTE=Anven11;49476303]It's still bad practice and less readable.[/QUOTE] Today I learned: [code] std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<int> dist(1, 11); int num = dist(mt) [/code] is more readable than [code] int num = ( rand() % 10 ) + 1 [/code] Do people even listen to themselves? Or is "readable" just becoming a buzzword people use now?: I use MongoDB because it's webscale and more readable!
[QUOTE=Tommyx50;49476655]Today I learned: [code] std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<int> dist(1, 11); int num = dist(mt) [/code] is more readable than [code] int num = ( rand() % 10 ) + 1 [/code] Do people even listen to themselves? Or is "readable" just becoming a buzzword people use now?: I use MongoDB because it's webscale and more readable![/QUOTE] Oh it's definitely a buzzword. It's most effective if you use it to criticize a language or a pattern you're not familiar with.
[QUOTE=Tommyx50;49476655]Today I learned: [code] std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<int> dist(1, 11); int num = dist(mt) [/code] is more readable than [code] int num = ( rand() % 10 ) + 1 [/code] Do people even listen to themselves? Or is "readable" just becoming a buzzword people use now?: I use MongoDB because it's webscale and more readable![/QUOTE] Because anyone reading [B](rand() % 10) + 1[/B] for the first time will totally understand what it does. Generating a random number between a [I]range[/I] should not be presented as [code]int num = rand() % (max - min) + min[/code] That makes no fucking sense. Last time I checked a range looked like this [code] int num = std::uniform_int_distribution<int>(min, max)(r) [/code]
[QUOTE=Anven11;49476805]Because anyone reading [B](rand() % 10) + 1[/B] for the first time will totally understand what it does. Generating a random number between a [I]range[/I] should not be presented as [code]int num = rand() % (max - min) + min[/code] That makes no fucking sense. Last time I checked a range looked like this [code] int num = std::uniform_int_distribution<int>(min, max)(r) [/code][/QUOTE] I would say that 100% of programmers that know what a uniform distribution is are probably familiar with the % (max - min) + min pattern. Though I do agree that an explicit range is probably better.
[QUOTE=Anven11;49476805]Because anyone reading [B](rand() % 10) + 1[/B] for the first time will totally understand what it does. Generating a random number between a [I]range[/I] should not be presented as [code]int num = rand() % (max - min) + min[/code] That makes no fucking sense. Last time I checked a range looked like this [code] int num = std::uniform_int_distribution<int>(min, max)(r) [/code][/QUOTE] I'm not going to disagree with the validity of your code but maybe, just maybe, what you're suggesting might make no sense to another programmer. Honestly for the intended purpose I think you're nitpicking. rand() might be less desirable for any number of reasons but for RNG most people are familiar with it and it hasn't presented itself as problematic for the majority of us.
[QUOTE=Tommyx50;49476655]Today I learned: [code] std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<int> dist(1, 11); int num = dist(mt) [/code] is more readable than [code] int num = ( rand() % 10 ) + 1 [/code] Do people even listen to themselves? Or is "readable" just becoming a buzzword people use now?: I use MongoDB because it's webscale and more readable![/QUOTE] Are you insane? Are you actually suggesting a new C++ developer to use a deprecated and potentially unsafe way of generating pseudo-random numbers instead of doing the right thing and using C++11? Let's begin by making the code snippets equivalent. Good version: [code] // Seed provider std::random_device rd; // Set a sane seed std::minstd_rand g(rd()); // Generate number in range [1, 11] auto num = std::uniform_int_distribution<int>{1, 11}(g); [/code] Shit version: [code] // Seed provider std::random_device rd; // Set a sane seed std::srand(rd()); // Generate number in range [1, 11] auto num = (std::rand() % 11) + 1; [/code] As you can see, the only difference between the code is the generation of the number. The seed provider and seeding the generator are an independent issue. Now, are you really going to argue that [code]auto num = (std::rand() % 11) + 1;[/code] is more readable than [code]auto num = std::uniform_int_distribution<int>{1, 11}(g);[/code] ? Because it isn't. The only positive thing about the first snippet is that it is terse - but guess what... we can solve that. [code] auto rnd_int = [&g](auto a, auto b){ return std::uniform_int_distribution<int>{a, b}(g); }; auto num = rnd_int(1, 11); [/code] Look at that again. [code] // Deprecated, unsafe, error-prone: auto num = (std::rand() % 11) + 1; // Modern, safe: auto num = rnd_int(1, 11); [/code]
[QUOTE=SupahVee;49477126]Are you insane? Are you actually suggesting a new C++ developer to use a deprecated and potentially unsafe way of generating pseudo-random numbers instead of doing the right thing and using C++11? Let's begin by making the code snippets equivalent. Good version: Shit version: As you can see, the only difference between the code is the generation of the number. The seed provider and seeding the generator are an independent issue. Now, are you really going to argue that [code]auto num = (std::rand() % 11) + 1;[/code] is more readable than [code]auto num = std::uniform_int_distribution<int>{1, 11}(g);[/code] ? Because it isn't. The only positive thing about the first snippet is that it is terse - but guess what... we can solve that. Look at that again. [/QUOTE] Ahm... [code]auto rnd_int2 = [&g](auto a, auto b){ return std::rand() % (b - a) + a; };[/code] Since we like making things equivalent. [code]// Deprecated, unsafe, error-prone: auto num = rnd_int2(1, 11); // Modern, safe: auto num = rnd_int(1, 11);[/code]
Well, his rand() example is objectively simpler and easier to digest for a novice than the "correct" way to do that. I put correct in apostrophes because it's all up to what the random number is used for. I doubt that for a "guess tha numbah :v:" you need anything more than that. The important thing is that he knows that this implementation has its faults and should not always be used. From there on, it's his choice. As for readability, it's subjective as well, based on previous experiences with other languages and/or tools. It is intuitive only if you already used it or something similar to it. You can't say whether it's readable or not without being biased. Unless it's perl.
just c++ things
Thanks for the help guys :) [editline]7th January 2016[/editline] [QUOTE=awcmon;49475908]I would be careful about saying you know a language Theres much more to a language than a few simple programs can touch on I wrote some stuff in a bunch of languages but i would never say that i know those langs just because of that Its almost like saying you know chinese when all you know are a handful of conversational phrases in mandarin[/QUOTE] You're right, I gotta watch what I say. Haha I should've said I know the basics of 6 languages to the extent that I could make an application thats somewhat well made. I haven't really used them, only around 4 I've actually used. PHP and HTML, I don't really use them because I'm not a web dev guy. Yeah I know HTML isn't a language but I mean, you get it haha.
[QUOTE=Darwin226;49477226]Ahm... [code]auto rnd_int2 = [&g](auto a, auto b){ return std::rand() % (b - a) + a; };[/code] Since we like making things equivalent. [code]// Deprecated, unsafe, error-prone: auto num = rnd_int2(1, 11); // Modern, safe: auto num = rnd_int(1, 11);[/code][/QUOTE] Missing the point, one is terse and safe and the other is terse and unsafe
Sorry, you need to Log In to post a reply to this thread.