• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=account;39800892]This is gonna get confusing. [code]([^ \t\n|><&]|(\\\| | \\< | \\> | \\&))*[/code] Dunno if this'll work, some languages aren't representable in regular expressions. But it matches 0 or more of either: A character from your character class, in other words anything besides those special characters, or One of '\|', '\<', '\>', or '\&'.[/QUOTE] Oh god my eyes.
[QUOTE=Meatpuppet;40691833]can someone PLEASE check this out this has been the reason i have stopped trying to develop a game engine and if i get it to work i will regain the will to work [url]http://stackoverflow.com/questions/16628515/text-not-rendering-at-all-with-freetype-glfw[/url] please [editline]18th May 2013[/editline] also python [code]divisorSums = {} def sumDivisors(num): global divisorSums total = 0 if num == 1: return 1 for i in xrange(num/2, 0, -1): if i in divisorSums: return divisorSums[i] else: if not num % i: total += i divisorSums[num] = total return total for i in range(100): print 'Sum of divisors of %i: %i\n' % (i, sumDivisors(i))[/code] this just outputs 1 for every number help i thought i knew how to memoize :([/QUOTE] Wouldn't you need to put that for loop inside an if-else block? if num == 1: return 1 else: (for loop)
Probably going to sound like an idiot, but I've been hearing that Lua is the easiest coding language to learn. That being said, I want to try to start on doing so. However, just a few questions: #1: Are executable files possible with it? #2: What programs would be best suited to making Lua files/scripts/executables/etc? [url=http://www.lua.org/download.html]I've tried downloading it from here[/url], but I don't know how to open .gz files, and the only other option I know of is LOVE, which is supposedly [b]kind of[/b] like Lua. Would that be the one to go with, or are there better alternatives?
I'm trying to work out a highscore saving option. Currently, I have the game count the score, and when the game is over, it can save the score to a text file. What I want is, when the game is over next time, to check the score in the text file, compare it to the current in-game score, and only save over the old score if the current in-game score is higher than the old score. I have checkScore(), which reads the score.txt file and saveScore(), which saves over the score. checkScore(): [code]public void checkScore() { try { BufferedReader br = new BufferedReader(new FileReader("score.txt")); String scoreLine; //Read File Line By Line while ((scoreLine = br.readLine()) != null) { int highscore= Integer.parseInt(scoreLine); } } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } }[/code] saveScore(): [code]public void saveScore() { try { String content = ""+highscore; File file = new File("score.txt"); if(!file.exists()) { file.createNewFile(); } FileWriter fw=new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); } catch(IOException e) { e.printStackTrace(); } }[/code] and finally when they're called: [code] /* game over code, etc. */ checkScore(); if(highscore<Score.score) /* Score.score is the current in-game score */ { highscore=Score.score; saveScore(); } [/code] my problem is that it saves over the score no matter what, even if it's lower edit: seconds after posting this and re-reading my post, I realize my issue was simply having put int before highscore in checkscore(). it's always the fuckin little things edit 2: however upon further inspection I've noticed that the score does not reset to 0 upon the game restarting. if I close the game and bring it up again it resets, but restarting the game from within the program will not reset it. edit 3: So to fix this I gave ownership of the score over to the player class, rather than the Score class, which only displays the score. The player, upon dying, saves the score if need be, and then immediately afterwords deletes the score again. the Score class now only displays Player.score rather than determines what the score is.
[QUOTE=AbeX300;40734648]Probably going to sound like an idiot, but I've been hearing that Lua is the easiest coding language to learn. That being said, I want to try to start on doing so. However, just a few questions: #1: Are executable files possible with it? #2: What programs would be best suited to making Lua files/scripts/executables/etc? [url=http://www.lua.org/download.html]I've tried downloading it from here[/url], but I don't know how to open .gz files, and the only other option I know of is LOVE, which is supposedly [b]kind of[/b] like Lua. Would that be the one to go with, or are there better alternatives?[/QUOTE] There is, as far as I'm aware, no compiler that generates native binaries from Lua, so there are no executables per se. The standard interpreter for Lua can be downloaded[url=http://luabinaries.sourceforge.net/download.html]here[/url]. (It's linked on the official download page, under "binaries") Also, LOVE is just a set of libraries wrapped for Lua usage, really. SFML, Box2D and PhysFS, at least. [editline]22nd May 2013[/editline] Basically, if you're trying to make games with Lua, I'd go with LOVE.
Can someone tell me why this works for defining an undefined variable in javascript? [code]"undefined"==typeof ivar&&(ivar=55)[/code]
[QUOTE=esalaka;40738494]There is, as far as I'm aware, no compiler that generates native binaries from Lua, so there are no executables per se..[/QUOTE] [url=http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#srlua]this[/url] is made by one of the Lua authors. It generates a Windows executable form a Lua script. AFAIK, internally it appends the Lua script to the end of an interpreter exe, so it can be distributed without Lua. [editline]22nd May 2013[/editline] [QUOTE=AbeX300;40734648]I don't know how to open .gz files[/QUOTE] WinRAR can open all sorts of compressed archives including gz files.
[QUOTE=vexx21322;40738621]Can someone tell me why this works for defining an undefined variable in javascript? [code]"undefined"==typeof ivar&&(ivar=55)[/code][/QUOTE] [i]typeof ivar[/i] will return [i]"undefined"[/i] if it is undefined, thus [i]"undefined"==typeof ivar[/i] will return [i]true[/i] if [i]ivar[/i] is undefined, [i]false[/i] otherwise. The operator [i]&&[/i] is a short-cutting logical and. That means when you have an expression like [i]true && ...[/i], [i]...[/i] needs to be evaluated (since you cannot know the result of the logical operation without it). However, when you have [i]false && ...[/i], then you already know that the result of the operation will be false, hence it will not evaluate the [i]...[/i]-part. So, if [i]"undefined"==typeof ivar[/i], [i]ivar[/i] will be set to [i]55[/i], otherwise it won't get evaluated, thus retain its old value.
[QUOTE=MakeR;40738665][url=http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#srlua]this[/url] is made by one of the Lua authors. It generates a Windows executable form a Lua script. AFAIK, internally it appends the Lua script to the end of an interpreter exe, so it can be distributed without Lua.[/QUOTE] Handy. LOVE actually has this function built-in: If you append the script/package/something to the interpreter (via, for instance, the Windows COPY utility) and run the resulting executable, it will automatically run your program. [QUOTE=MakeR;40738665] WinRAR can open all sorts of compressed archives including gz files.[/QUOTE] I'd personally suggest 7zip.
[QUOTE=ZeekyHBomb;40738695][i]typeof ivar[/i] will return [i]"undefined"[/i] if it is undefined, thus [i]"undefined"==typeof ivar[/i] will return [i]true[/i] if [i]ivar[/i] is undefined, [i]false[/i] otherwise. The operator [i]&&[/i] is a short-cutting logical and. That means when you have an expression like [i]true && ...[/i], [i]...[/i] needs to be evaluated (since you cannot know the result of the logical operation without it). However, when you have [i]false && ...[/i], then you already know that the result of the operation will be false, hence it will not evaluate the [i]...[/i]-part. So, if [i]"undefined"==typeof ivar[/i], [i]ivar[/i] will be set to [i]55[/i], otherwise it won't get evaluated, thus retain its old value.[/QUOTE] I figured it was something like that, but I didn't know javascript had two types of short conditionals. Thanks.
So, I'm kinda new here, and I have a question for somebody that knows something about programming, and maybe physics. What should I do to make some sort of a water simulation? I'm using C++ and I was hoping to use a 2D array of structs. Each struct would hold the water level, vertical velocity of the water and floor level for each pixel. I'm having trouble figuring out what rules to apply to each pixel to get a nice flowing water effect.
An expensive but easy way is to simulate the water as a mass of vertices, where each vertex interacts with those near it by soft collision. Pressure and such come naturally as a result of the interactions between the vertices. [editline]22nd May 2013[/editline] It's not very realistic but it's cool.
[QUOTE=Porcuponic;40739544]So, I'm kinda new here, and I have a question for somebody that knows something about programming, and maybe physics. What should I do to make some sort of a water simulation? I'm using C++ and I was hoping to use a 2D array of structs. Each struct would hold the water level, vertical velocity of the water and floor level for each pixel. I'm having trouble figuring out what rules to apply to each pixel to get a nice flowing water effect.[/QUOTE] 1D velocity is probably not enough, if you want it to flow with inertia you need to add horizontal velocity and base the interactions on mass/volume transfer between the cells.
[code] public static int countVowel(String str){ int x = str.length(); //length String int counter = 0; for (int i=0;i<=x;i++){ String c = str.substring(); if (c.equals("a") ){ counter++; } } return counter; } [/code] I'm trying to write a method that will count all the vowels in a string and returns the number of vowels. I'm just doing the letter a for now, to keep it simple. I can't figure out what to put in the parameters for the substring. I think x-(x-i) will work for the first parameter, but I don't know about the second one.
[QUOTE=wlitsots;40747608][code] public static int countVowel(String str){ int x = str.length(); //length String int counter = 0; for (int i=0;i<=x;i++){ String c = str.substring(); if (c.equals("a") ){ counter++; } } return counter; } [/code] I'm trying to write a method that will count all the vowels in a string and returns the number of vowels. I'm just doing the letter a for now, to keep it simple. I can't figure out what to put in the parameters for the substring. I think x-(x-i) will work for the first parameter, but I don't know about the second one.[/QUOTE] x-(x-i) == i i.e. your loop variable/index in the string is correct for the first parameter. The second one is the exclusive end (the index of the first character you don't want). Instead of substring you can also use charAt(int index), which returns exactly one character. It's a char value, so you'll need to compare to 'a' instead of "a". (You can use == for that with chars.) Edit: Your loop condition is incorrect though, i<=x means that i can reach the value of x, and the length of the string as index points behind the end of the string, as the indices start with 0.
[QUOTE=Tamschi;40747797]x-(x-i) == i i.e. your loop variable/index in the string is correct for the first parameter. The second one is the exclusive end (the index of the first character you don't want). Instead of substring you can also use charAt(int index), which returns exactly one character. It's a char value, so you'll need to compare to 'a' instead of "a". (You can use == for that with chars.) Edit: Your loop condition is incorrect though, i<=x means that i can reach the value of x, and the length of the string as index points behind the end of the string, as the indices start with 0.[/QUOTE] Thanks, I tried using charAt at first but I didn't know how to compare it. I have this now and it works. [code] public static int countVowel(String str){ int x = str.length(); //length String int counter = 0; for (int i=0;i<x;i++){ char c = str.charAt(i); if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){ counter++; } } return counter; } [/code] If I wanted to print each letter of a String, can I still use charAt?
Yeah, System.out.write(str.charAt(i)); works.
I've been thinking about terrain generation for the last couple of days now. I'd like to recreate the following effect: [IMG]https://lh3.googleusercontent.com/xLsYHzNpBEagFJPm6eWKXldnmQqgHFik9yProxSa23SmpsRh1AV8qqQyxkcq0gqpF71T2su7Te0Oqd_Gy5_vNu1YHIKnIKbg3E468yU9UctDtWSO6fw9WNOYMg[/IMG] I've also written a document on how I [I]might[/I] tackle this problem, however I don't feel quite confident in my solution. ( [URL="https://docs.google.com/document/d/1CDaJrzC4g8burrhx3l3HbtFQEbUbx303ljLWyGF5Khk/edit"]https://docs.google.com/document/d/1CDaJrzC4g8burrhx3l3HbtFQEbUbx303ljLWyGF5Khk[/URL] ) I've also read a great article by NVIDIA ( [URL]http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html[/URL] ) but I feel the solution might be overkill for my problem. Can anyone here please enlighten me on a possible solution to generate this kind of terrain? [editline]23rd May 2013[/editline] How well would the diamond-square algorithm function in recreating the effect of the image above ( [url]http://paulboxley.com/blog/2011/03/terrain-generation-mark-one[/url] )
[QUOTE=Asgard;40751831]I've been thinking about terrain generation for the last couple of days now. I'd like to recreate the following effect: [IMG]https://lh3.googleusercontent.com/xLsYHzNpBEagFJPm6eWKXldnmQqgHFik9yProxSa23SmpsRh1AV8qqQyxkcq0gqpF71T2su7Te0Oqd_Gy5_vNu1YHIKnIKbg3E468yU9UctDtWSO6fw9WNOYMg[/IMG] I've also written a document on how I [I]might[/I] tackle this problem, however I don't feel quite confident in my solution. ( [URL="https://docs.google.com/document/d/1CDaJrzC4g8burrhx3l3HbtFQEbUbx303ljLWyGF5Khk/edit"]https://docs.google.com/document/d/1CDaJrzC4g8burrhx3l3HbtFQEbUbx303ljLWyGF5Khk[/URL] ) I've also read a great article by NVIDIA ( [URL]http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html[/URL] ) but I feel the solution might be overkill for my problem. Can anyone here please enlighten me on a possible solution to generate this kind of terrain? [editline]23rd May 2013[/editline] How well would the diamond-square algorithm function in recreating the effect of the image above ( [url]http://paulboxley.com/blog/2011/03/terrain-generation-mark-one[/url] )[/QUOTE] If you don't want overhangs you can scatter vertices on a plane and then create triangles between them (for example by starting with the area and adding points inside too large areas). If you combine that with a common heightmap algorithm you should get an organic, geometric look. You can also make the maximum extents of a triangle dependent on the steepness, that will automatically tesselate cliffs. Edit: You can most likely approximate the cliffs from the waterfall image by distorting horizontally after you finished the terrain generation (based on steepness, material...). Allowing additional triangle size along a cliff should give you similar thin faces.
[QUOTE=Tamschi;40752711]If you don't want overhangs you can scatter vertices on a plane and then create triangles between them (for example by starting with the area and adding points inside too large areas). If you combine that with a common heightmap algorithm you should get an organic, geometric look. You can also make the maximum extents of a triangle dependent on the steepness, that will automatically tesselate cliffs.[/QUOTE] Alright, that's more-or-less what I wrote earlier. By controlling the intensity of the randomization I could theoretically generate different kinds of terrain. Applying a fBm beforehand would hopefully create the organic look. And I could reuse the heightmap generated for fluid simulation, possibly. :V:
I'd need a way in C# to hook into whenever a USB device has been connected/disconnected. I've read up into it about services and stuff, but I don't quite understand it. Could I get some help?
[QUOTE=Donkie;40765096]I'd need a way in C# to hook into whenever a USB device has been connected/disconnected. I've read up into it about services and stuff, but I don't quite understand it. Could I get some help?[/QUOTE] Look at this, a tutorial about what you're searching for. [URL="http://www.codeproject.com/Articles/18062/Detecting-USB-Drive-Removal-in-a-C-Program"]Link.[/URL]
[code] #include "ranNumGuess.h" #include <iostream> #include <cstdlib> using namespace std; ranNumGuess::ranNumGuess() { //ctor } int ranNumGuess::ranNumGen() { num = rand()%(100); printQ(); } void ranNumGuess::printQ() { cout << "Guess the number: "; cin >> guess; result(); } void ranNumGuess::result() { while (guess != num) { if (guess > num) { cout << "Your guess was too high.\n"; printQ(); } else { cout << "Your guess was too low.\n"; printQ(); } counter++; } cout << "You guessed correctly!\n"; cout << "You guessed " << counter << " times.\n"; } [/code] Everytime I run this code it prints [code] cout << "You guess correctly!\n"; cout << "You guessed " << counter << " times.\n"; [/code] those lines n amount of times once I guess the correct number. Also the first time it prints counter is always 0. Those 2 lines are outside of the while loop so I don't understand why they get printed multiple times.
You call printQ if the guess is wrong, which will call result again, but you're using a while loop to get new results in so every time you guess wrong a new loop is started but the old loop is still going. When you finally get it right all those result calls will each print the correct guess code. Change your while to an if, that should fix it. I think.
I changed it to this and it works now. [code] void ranNumGuess::result() { if (guess > num) { cout << "Your guess was too high.\n"; counter++; printQ(); } else if (guess < num) { cout << "Your guess was too low.\n"; counter++; printQ(); } else { cout << "You guessed correctly!\n"; counter++; cout << "You guessed " << counter << " times."; } } [/code]
-snip- Didn't see the new page. Carry on.
Can anyone tell me why my output is just 100,000,000 and not adding? It seems my first if statement is just repeating itself. Hmm. Such a beginner here. [code] import java.io.IOException; public class main { static boolean Running = true; public static void main(String[] args) throws IOException { int startNumber = 0; int countingAddition = 100000000; int outputInteger = 0; System.out.println("system.out worked!"); while (Running = true) { if (startNumber == 0) { System.out.println("looping gameRunning " +outputInteger); outputInteger = startNumber + countingAddition; } else if (outputInteger > 1) { System.out.println("looping gameRunning " +outputInteger); outputInteger = outputInteger + countingAddition; } else { break; } } System.out.println("\n"); System.out.println("Program Terminated!\n"); System.out.println("Press ANY key to QUIT"); System.in.read(); System.exit(0); } } [/code]
[QUOTE=Superwafflez;40774572] Can anyone tell me why my output is just 100,000,000 and not adding? [/QUOTE] I think [code] if (startNumber == 0) { System.out.println("looping gameRunning " +outputInteger); outputInteger = startNumber + countingAddition; } else if (outputInteger > 1) { System.out.println("looping gameRunning " +outputInteger); outputInteger = outputInteger + countingAddition; } [/code] should be [code] if (startNumber == 0) { System.out.println("looping gameRunning " +outputInteger); outputInteger = startNumber + countingAddition; } if (outputInteger > 1) { System.out.println("looping gameRunning " +outputInteger); outputInteger = outputInteger + countingAddition; } [/code] Considering startNumber is always 0, the "if (outputInteger > 1)" branch will never be executed because it'll always execute the branch "if (startNumber==0)" first. Also, I'm not quite sure (especially considering it's 4:47 AM right now), but in the branch [code] if (startNumber == 0) { System.out.println("looping gameRunning " +outputInteger); outputInteger = startNumber + countingAddition; } [/code] shouldn't [code]outputInteger = startNumber + countingAddition;[/code] be [code]outputInteger += startNumber + countingAddition;[/code] Here's the changes done in a pastebin entry: [URL="http://pastebin.com/E9CiBB0J"]Link[/URL]
That actually did work, though the program then terminated after these two lines of output: [code] looping gameRunning 2100000000 looping gameRunning -2094967296 [/code] Ah, max value of int32. Disregard this.
hi i'm a beginner (emphasis on beginner) in C# i was challenged by my friend to make this loop after they have chosen a door: [code]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { //Console.WriteLine("Please type something and press Enter"); //string userValue; //userValue = Console.ReadLine(); //Console.WriteLine("You typed: " + userValue); //Console.ReadLine(); Console.WriteLine("Would you prefer what is behind door number 1, 2 or 3?"); string userValue = Console.ReadLine(); /* string message = ""; if (userValue == "1") message = "You won a new car!"; else if (userValue == "2") message = "You won nothing.!"; else if (userValue == "3") message = "You won a new keychain!"; else message = "Sorry, that's an invalid choice. Please try again."; */ string message = (userValue == "1") ? "dragon dildo" : "regular dildo"; Console.WriteLine("You won a {0}! You typed {1}. \n Would you like to play again?", message, userValue); string userValue2 = Console.ReadLine(); if (userValue2 == "yes") { Console.WriteLine("Would you prefer what is behind door number 1, 2 or 3?"); } else { Console.WriteLine("You suck.)"); } Console.ReadLine(); } } }[/code] i started but i was stumped as to how to loop
Sorry, you need to Log In to post a reply to this thread.