• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=jA_cOp;25497527]You'll want to paste the entire file, and the exact error message. (Also, Lua is not an acronym)[/QUOTE] I copied the wrong function. :downs: Whole file: [url]http://pastebin.com/DD8hbxyK[/url] Error message: [url]http://i51.tinypic.com/2cd72go.png[/url]
You're missing an 'end' at line 18 after the one that closes the if.
Take the end from line 15 and move it to line 18.
[QUOTE=ralle105;25498721]Take the end from line 15 and move it to line 18.[/QUOTE] Thanks! [img]http://www.facepunch.com/fp/ratings/heart.png[/img]
[QUOTE=Phyxius;25498508]I copied the wrong function. :downs: Whole file: [url]http://pastebin.com/DD8hbxyK[/url] Error message: [url]http://i51.tinypic.com/2cd72go.png[/url][/QUOTE] You'd see it right away if you paid attention to indentation. For example, here's the erroring code after proper indentation: [lua] local function doWorldCollision(temp, newx, newy) if newy < 0 then temp.direction = math.abs(360 - temp.direction) end if newy > temp.y then if (temp.img.getHeight() + newy) > love.graphics.getHeight() then temp.direction = math.abs(360 - temp.direction) end end else temp.y = newy return temp end [/lua] It's now obvious that the last few lines there are non-sense. Here's what you probably wanted: [lua] local function doWorldCollision(temp, newx, newy) if newy < 0 then temp.direction = math.abs(360 - temp.direction) end if newy > temp.y then if (temp.img.getHeight() + newy) > love.graphics.getHeight() then temp.direction = math.abs(360 - temp.direction) end else temp.y = newy end return temp end [/lua]
[code] void run(string instructions) { stack<int> loops; bool noparse = false; for(int strpos = 0; strpos < instructions.size(); strpos++) { string cmd = instructions.substr(strpos, 1); if(!noparse) { if(cmd.compare(">") != 0) pos++; if(cmd.compare("<") != 0) pos--; if(cmd.compare("+") != 0) tape[pos]++; if(cmd.compare("-") != 0) tape[pos]++; if(cmd.compare("[") != 0) { if(tape[pos] > 0) { loops.push(strpos); } else noparse = true; } } if(cmd.compare("]") != 0) { if(noparse) noparse = false; else { if(tape[pos] > 0) { strpos = loops.top(); loops.pop(); } } } } } [/code] So I thought this would work, but it doesn't. I have abosuletely no idea where I went wrong. Now, >++ as a program works. But the hello world program (>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.) doesn't. Anyone wanna guess why? [editline]19th October 2010[/editline] [code] void run(string instructions) { stack<int> loops; bool noparse = false; for(int strpos = 0; strpos < instructions.size(); strpos++) { string cmd = instructions.substr(strpos, 1); if(!noparse) { if(cmd.compare(">") != 0) pos++; if(cmd.compare("<") != 0) pos--; if(cmd.compare("+") != 0) tape[pos]++; if(cmd.compare("-") != 0) tape[pos]++; if(cmd.compare("[") != 0) { if(tape[pos] > 0) { loops.push(strpos); } else noparse = true; } } if(cmd.compare("]") != 0) { if(noparse) noparse = false; else { if(tape[pos] > 0) { strpos = loops.top(); loops.pop(); } } } } } [/code] So I thought this would work, but it doesn't. I have abosuletely no idea where I went wrong. Now, >++ as a program works. But the hello world program (>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.) doesn't. Anyone wanna guess why? [editline]19th October 2010[/editline] [code] void run(string instructions) { stack<int> loops; bool noparse = false; for(int strpos = 0; strpos < instructions.size(); strpos++) { string cmd = instructions.substr(strpos, 1); if(!noparse) { if(cmd.compare(">") != 0) pos++; if(cmd.compare("<") != 0) pos--; if(cmd.compare("+") != 0) tape[pos]++; if(cmd.compare("-") != 0) tape[pos]++; if(cmd.compare("[") != 0) { if(tape[pos] > 0) { loops.push(strpos); } else noparse = true; } } if(cmd.compare("]") != 0) { if(noparse) noparse = false; else { if(tape[pos] > 0) { strpos = loops.top(); loops.pop(); } } } } } [/code] So I thought this would work, but it doesn't. I have abosuletely no idea where I went wrong. Now, >++ as a program works. But the hello world program (>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.) doesn't. Anyone wanna guess why?
Tried to switch to Visual Studio 2010, because I liked the GUI. Tried to compile TinyXml++. The fucking thing won't read the libs :saddowns: I also compiled SFML2 by running the VS2008 build files and then compiling them in VS2010. Hope that works. For some odd reason, whenever I try to open a proj file, it asks me if I want to open with Visual Studio C++ 2010 or Visual Studio C++ 10. How do I fix that, as well as the TinyXml++ thing?
[QUOTE=WTF Nuke;25519591]Tried to switch to Visual Studio 2010, [b]because I liked the GUI[/b]. Tried to compile TinyXml++. The fucking thing won't read the libs :saddowns: I also compiled SFML2 by running the VS2008 build files and then compiling them in VS2010. Hope that works. For some odd reason, whenever I try to open a proj file, it asks me if I want to open with Visual Studio C++ 2010 or Visual Studio C++ 10. How do I fix that, as well as the TinyXml++ thing?[/QUOTE] Hmm
[QUOTE=WTF Nuke;25519591]Tried to switch to Visual Studio 2010, [b]because I liked the GUI[/b]. Tried to compile TinyXml++. The fucking thing won't read the libs :saddowns: I also compiled SFML2 by running the VS2008 build files and then compiling them in VS2010. Hope that works. For some odd reason, whenever I try to open a proj file, it asks me if I want to open with Visual Studio C++ 2010 or Visual Studio C++ 10. How do I fix that, as well as the TinyXml++ thing?[/QUOTE] Hmm
Does anyone know how to find the directory the program is being run from in C#? I want my programs to work if all of the files are in the same place, regardless of the location.
[QUOTE=SamPerson123;25521818]Does anyone know how to find the directory the program is being run from in C#? I want my programs to work if all of the files are in the same place, regardless of the location.[/QUOTE] You can use Application.StartupPath, but it sounds like you could just use relative paths.
[QUOTE=jA_cOp;25521894]You can use Application.StartupPath, but it sounds like you could just use relative paths.[/QUOTE] So how exactly do I use relative paths? I've looked around, but I can't really find anything about how to use them.
[QUOTE=SamPerson123;25522187]So how exactly do I use relative paths? I've looked around, but I can't really find anything about how to use them.[/QUOTE] A relative path is relative to the working directory. The default working directory is the directory from which the program was executed, which may or may not be the directory in which the program lies. On Windows, for example, when the executable or a shortcut to it is double-clicked in explorer, the working directory is set to that of the executable, which means Application.StartupPath will be equal to the working directory. So if one wanted to bundle configuration, data or DLL files with your application, one would usually just use relative paths to refer to them. A relative path is simply a path which isn't rooted with some sort of prefix, like a hard-drive letter on Windows, or the root path ('/') on Unix-likes, for example: [cpp] string text = File.ReadAllText("test.txt"); [/cpp] "test.txt" is a relative path and will be looked for in the working directory. If you run your program in the same directory your program lies (e.g., double-clicking it), "test.txt" is looked for in the same directory as the executable file. Because of relative paths, most programs don't need to use this kind of information, but you asked, so: to get the directory from which the program was run (working directory), you can use Directory.GetCurrentDirectory. To set the working directory, use Directory.SetCurrentDirectory. Application.StartupPath is the directory in which the executable file lies.
[QUOTE=neos300;25516007][code]*code*[/code] So I thought this would work, but it doesn't. I have abosuletely no idea where I went wrong. Now, >++ as a program works. But the hello world program (>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.) doesn't. Anyone wanna guess why?[/QUOTE] [cpp]if(cmd.compare("+") != 0) tape[pos]++; if(cmd.compare("-") != 0) tape[pos]++;[/cpp] Correct me if I'm wrong, but shouldn't one of those be -- instead of ++? :)
I have such thing in my program: [cpp]transform(Data.begin(), Data.end(), Data.begin(), boost::bind(&boost::trim_copy<string>, _1, locale()));[/cpp] It takes "vector<string> Data" and trims all strings in Data. Is there any less ugly way to achieve that?
[cpp]BOOST_FOREACH(string &str, Data) boost::trim(str);[/cpp]
I totally forgot BOOST_FOREACH. I can't wait for C++0x to be generally supported so I can make my life easier : [url]http://en.wikipedia.org/wiki/C%2B%2B0x#Range-based_for-loop[/url]
[QUOTE=Chris220;25525440][cpp]if(cmd.compare("+") != 0) tape[pos]++; if(cmd.compare("-") != 0) tape[pos]++;[/cpp] Correct me if I'm wrong, but shouldn't one of those be -- instead of ++? :)[/QUOTE] And this, folks, is why you always do unit testing.
[QUOTE=shill le 2nd;25530357]And this, folks, is why you always do unit testing.[/QUOTE] ...Or the lazy man's solution. Debug messages, debug messages everywhere.
[QUOTE=esalaka;25531139]...Or the lazy man's solution. Debug messages, debug messages everywhere.[/QUOTE] That's the approach that requires more work, so meh.
[QUOTE=gparent;25531203]That's the approach that requires more work, so meh.[/QUOTE] [editline]20th October 2010[/editline] What, where's content. Anyway, yeah, it might require more work, but debug messages can be done inline, and with functions such as printf and the easiness of using std::cout in C++, it's not hard to output even more exotic data types.
[QUOTE=esalaka;25531288][editline]20th October 2010[/editline] What, where's content. Anyway, yeah, it might require more work, but debug messages can be done inline, and with functions such as printf and the easiness of using std::cout in C++, it's not hard to output even more exotic data types.[/QUOTE] It's even easier to put a breakpoint and press "Debug", then look at the memory.
[QUOTE=gparent;25531582]It's even easier to put a breakpoint and press "Debug", then look at the memory.[/QUOTE] Well... sure. But I always forget I can do that. :v:
I'm in the preplanning stages of a project which may involve a huge accessible lateral area. My main concern is the size and it's effect on datatype precision. Floats would get me the required precision, but at the edges of the map, I'd start to lose that, restricting my maximum range to a certain value. Changing units or scaling things won't help as it will all have to be translated back into floats for (realtime 3D) rendering, right? (for instance, doubles would theoretically solve my problem) Any suggestions? Or should I just limit the size? I know there's many games out there with large areas that have acceptable precision. How are they doing this?
[QUOTE=Pirate Ninja;25521382]Hmm[/QUOTE] What? I like to upgrade when I can. And why is liking the GUI so bad?
[QUOTE=BMCHa;25540148]I'm in the preplanning stages of a project which may involve a huge accessible lateral area. My main concern is the size and it's effect on datatype precision. Floats would get me the required precision, but at the edges of the map, I'd start to lose that, restricting my maximum range to a certain value. Changing units or scaling things won't help as it will all have to be translated back into floats for (realtime 3D) rendering, right? (for instance, doubles would theoretically solve my problem) Any suggestions? Or should I just limit the size? I know there's many games out there with large areas that have acceptable precision. How are they doing this?[/QUOTE] [url=http://scottbilas.com/files/2003/gdc_san_jose/continuous_world_paper.html]Read this[/url]
I am using PDCurses and C++ to program a simple roguelike. How would I print the values of variables to the screen? std::cout works but I realise I can't use it. since printw() only takes a string as an argument and addch() only a char.
[QUOTE=Armandur;25547446]I am using PDCurses and C++ to program a simple roguelike. How would I print the values of variables to the screen? std::cout works but I realise I can't use it. since printw() only takes a string as an argument and addch() only a char.[/QUOTE] [cpp] std::stringstream ss; ss << varOfAnyFundamentalType; printw( ss.str().c_str() ); [/cpp] Or something like that. Stringstreams.
[QUOTE=esalaka;25547468][cpp] std::stringstream ss; ss << varOfAnyFundamentalType; printw( ss.str().c_str() ); [/cpp] Or something like that. Stringstreams.[/QUOTE] Thanks. Had to read up on it on C++ reference and solved it like this: [cpp] ////////////// //DEBUG FOR PC ////////////// char ssY[5] , ssX[5] ; std::stringstream pcY (std::stringstream::in | std::stringstream::out); std::stringstream pcX (std::stringstream::in | std::stringstream::out); pcY << PC.y; pcX << PC.x; pcY >> ssY; pcX >> ssX; mvprintw(89,0,"PC Coordinates"); mvaddch(90,0,'Y'); mvprintw(90,1,(ssY)); mvaddch(90,4,'X'); mvprintw(90,5,(ssX)); ////////////////// //END DEBUG FOR PC ////////////////// [/cpp] [editline]21st October 2010[/editline] And I had to include #sstream of course :)
I think you could've done [cpp]std::stringstream pcY; pcY << PC.y PC.x; pcY >> ssY >> ssX; // This might be >> ssX >> ssY, not sure[/cpp]
Sorry, you need to Log In to post a reply to this thread.