• What do you need help with? Version 5
    5,752 replies, posted
Just borrowing this from the WAYWO thread: [QUOTE=Jawalt;38066803][img]http://24.media.tumblr.com/tumblr_m8uhnbZZoM1rzupqxo1_500.png[/img] I found this on the website that's from and it sums up XML so perfectly.[/QUOTE] Any suggestions what to use instead of XML? For example to describe how a level are build. Would be nice with some kind of component style data language so you could list all entities you want and for every entity all the component data needed. Probably nesting would be needed for sub components and so on.
Yo. Im trying to have an if statement that checks if my array is on a specific position. Array is hybel[3][6] and i want it check if its [3][j] if you get what i mean. I am to subract a value from an int, but only if hybel is in position [3][j] (the last coordinate doesn't matter what it's at. Hope i made my question understandable. (java btw if anyone wondered) EDIT: Should be 2 and not 3 in [2][j].
You store the variables used to index the array and then check if the first index variable is 3? However it seem to be a bad solution to whatever problem you want to solve to just do a certain thing if the index variable is in a certain position.
[QUOTE=AlienCat;38073459]Any suggestions what to use instead of XML? For example to describe how a level are build. Would be nice with some kind of component style data language so you could list all entities you want and for every entity all the component data needed. Probably nesting would be needed for sub components and so on.[/QUOTE] I have no experience with it, but JSON over XML seems to be the general opinion in here (and elsewhere).
[QUOTE=jaooe;38048004]Is there a function to map a value? More precisely, what would that function look like so that, f(100) = 170 f(50) = 0 f(0) = -170 I haven't done math in about 4 years and I'm thinking that percentages are involved?[/QUOTE] Here's a generic one: [code] float map(float cur, float min, float max) { return (cur - min) / (max - min); } float lerp(float min, float max, float amount) { return min + (max - min) * amount; } float lerp_changerange(float cur, float oldMin, float oldMax, float newMin, float newMax) { float percent = map(cur, oldMin, oldMax); return lerp(newMin, newMax, percent); } [/code] Your function could be done like this: [code] float result100 = lerp_changerange(100, 0, 100, -170, 170); //result = 170 float result50 = lerp_changerange(50, 0, 100, -170, 170); //result = 0 float result0 = lerp_changerange(0, 0, 100, -170, 170); //result = -170 [/code] that function finds the normalised position of the 1st argument inside the 2nd/3rd arguments e.g. 50, 0, 100 would give you 0.5 since 50 is half way between 0 and 100. then it picks a point between the 4th and 5th arguments using that result, e.g. 0.5 between -170 and 170 = 0 (half way). at some point you may want to clamp the result (make sure it stays between newMin and newMax), if you do then beware that the above has no problem with min being bigger than max, but your clamping might not work if it assumes min < max.
[QUOTE=AlienCat;38073459]Just borrowing this from the WAYWO thread: Any suggestions what to use instead of XML? For example to describe how a level are build. Would be nice with some kind of component style data language so you could list all entities you want and for every entity all the component data needed. Probably nesting would be needed for sub components and so on.[/QUOTE] As file size and loading speed are (usually) important for games, the most common solution is a custom binary format that works well for one game but not for others. If you don't want to write a level editor, you could try JSON (if it's better than XML in your case) or create your own, stricter format if you want to improve speed and size of your data. The solution really depends on how much of the game is hard coded and how much documentation you want to force in the files. I'm pretty sure recursion is unnecessary though, you could just have flat tables and store the references by name. You can resolve them after parsing everything else that way, to make the format order-independent and allow cyclic references.
[QUOTE=MakeR;38073406]Could you not just register the function then run the file then unregister the function?[/QUOTE] There is no way to unregister functions with Luainterface. Also the function is needed almost all the time.
[QUOTE=Funley;38078310]There is no way to unregister functions with Luainterface. Also the function is needed almost all the time.[/QUOTE] [url=http://stackoverflow.com/questions/1224708/how-can-i-create-a-secure-lua-sandbox]Sandbox[/url] the file?
[QUOTE=AlienCat;38074972]You store the variables used to index the array and then check if the first index variable is 3? However it seem to be a bad solution to whatever problem you want to solve to just do a certain thing if the index variable is in a certain position.[/QUOTE] I kinda got it working, but not as it should. It does what its supposed to, subtract an int value if its [2][j] but it also does it for all of the j's that are the same as what ever it says in the array. Errrr.. Say i enter 3A. It seems that 3 is in position 2 which it should and prints, but it also prints on all the other positions with A, like 1A, 2A.
Hello, I'm making a compiler currently. I wanted to know where and how I should store the strings; more specifically, the strings which are used for parsing (the actual keywords in the programming language like int32) and those which are used for warning and error messages. Should I just keep them in the constant data segment in the executable or should I load them from a file. The compiler is for a full scale programming language so there are a LOT of strings, which is why I'm worried plopping them all in the data segments could be problematic. Thanks :)
So I reformatted my hard drive and forgot to backup my MySQL database. Now I'm trying to salvage files using some software but I don't know what file to look for. Does anyone know the name/path of the files that MySQL uses to store databases?
nvm
[QUOTE=Electroholic;38084840]So I reformatted my hard drive and forgot to backup my MySQL database. Now I'm trying to salvage files using some software but I don't know what file to look for. Does anyone know the name/path of the files that MySQL uses to store databases?[/QUOTE] /var/lib/mysql
[QUOTE=Nick Lomax;38078900]I kinda got it working, but not as it should. It does what its supposed to, subtract an int value if its [2][j] but it also does it for all of the j's that are the same as what ever it says in the array. Errrr.. Say i enter 3A. It seems that 3 is in position 2 which it should and prints, but it also prints on all the other positions with A, like 1A, 2A.[/QUOTE] Sounds like some kind of error in your code then and I have no idea what your code look likes. [editline]18th October 2012[/editline] [QUOTE=Tamschi;38078277]As file size and loading speed are (usually) important for games, the most common solution is a custom binary format that works well for one game but not for others. If you don't want to write a level editor, you could try JSON (if it's better than XML in your case) or create your own, stricter format if you want to improve speed and size of your data. The solution really depends on how much of the game is hard coded and how much documentation you want to force in the files. I'm pretty sure recursion is unnecessary though, you could just have flat tables and store the references by name. You can resolve them after parsing everything else that way, to make the format order-independent and allow cyclic references.[/QUOTE] Thank you! That answer was lurking in my head. I try to do little hard coding cause I want to create a modular game, but I would probably end up with going nowhere. For now, I will just hard code the level instead cause I do not feel for doing a level editor. However, since my game are going to be an arena style game, I might be able to use the bsp format and radiant or something. But I would probably just change my mind because I might at some point want to use terrains and additional features that I do not think I can do in an existing radiant style editor.
Java/Android question: How can I add function/method into Queue like Queue(new triangle(...coordinates'nstuff)); then later in other thread execute this? I don't want this stuff to execute in same thread I am adding into queue, but separate thread.
I am using C# and I am making a application popup when pressing 2 keys (with some low level keyboard hooks) When I press escape the application hides with this.hide() and then I show it again using this.show(). This works find until the user doesn't use escape but just clicks on a other application on screen or in the toolbar in the bottom. How would I work around this ?
I wrote this little program to do simple analysis of text from input or from a file, but I would like to do the process that splits the text and does the analysis after the switch statement rather than inside but there is a problem with local variables, how would I avoid this problem? [url]http://pastebin.com/xNw91LZG[/url]
Does anyone know how to read an external .txt file, and import the data into an array in C?
[QUOTE=JakeAM;38094615]I would like to do the process that splits the text and does the analysis after the switch statement rather than inside but there is a problem with local variables, how would I avoid this problem?[/QUOTE] The better way to do this would be to use the programs args to determine behavior. If they give an argument, try to open that filename and read it. If they don't, use System.in. The beauty of stdin is that it lets you treat user input the same way as a file. This is how a lot of unix programs behave. [QUOTE=Rexen;38095274]Does anyone know how to read an external .txt file, and import the data into an array in C?[/QUOTE] [code] #include <stdio.h> ... FILE* fp = fopen("filename.txt", "r"); fseek(fp, 0, SEEK_END); long size = ftell(fp); char text[size + 1]; fseek(fp, 0, SEEK_SET); fread(text, 1, size, fp); text[size] = '\0'; ... fclose(fp); [/code] Note that that's only good, valid code if you're using C99. For older version you'll need to malloc text and variable declarations should all be at the beginning.
I find that when I research C++ commands, I wanna go for something that is a quick and efficient as possible, which makes me tend to go for the lower-level functions. I feel dissatisfied a lot of the time, and I sometimes wonder if even assembly would be good enough for me.
[QUOTE=JakeAM;38094615]I wrote this little program to do simple analysis of text from input or from a file, but I would like to do the process that splits the text and does the analysis after the switch statement rather than inside but there is a problem with local variables, how would I avoid this problem? [url]http://pastebin.com/xNw91LZG[/url][/QUOTE] I think you can define the variable outside of the switch without assigning it if you add a [I]default: throw new SomeException();[/I] to the switch statement.
In C# I'm pattern-matching an array "Objects" to ensure that I can do some stuff on them [cpp]if (!PatternMatch(new Type[] { typeof(A), typeof(B), typeof(C) }, Objects)) return false;[/cpp] However this looks unwieldy and ugly and I'd like to replace it with something simpler like [cpp]if (!PatternMatch("A B C", Objects)) return false; or if (!PatternMatch(PATTERN(A, B, C), Objects)) return false;[/cpp] but without the cost of having to parse the string into a pattern every time the function is called. So is there a nice solution to preferably construct the pattern at compile-time or once upon initialization? I guess I could create a static dictionary that associates the strings with corresponding patterns, but even that seems a bit overboard for a problem that could be solved with macro expansion or something [editline]19th October 2012[/editline] Actually I think I'll go with the dictionary. It should save some memory for duplicate patterns and it's quick to implement. But if anyone has any other ideas, I'd like to hear them!
C++ troubles ahead. So I have a templated constructor (based off the STL containers) for a templated class that takes two input iterators. The question is, how do I make sure that the value type of the iterator is the same as the value type of my actual class? Quick example code. [cpp] template<typename _Val> struct Foo { template<typename _InputIter> Foo(_InputIter first, _InputIter last) { //I want to check the value type of the iterators here, preferably at compile time } std::list<_Val> data; //Some arbitrary data storage method goes here }; [/cpp]
[QUOTE=ECrownofFire;38102229]C++ troubles ahead. So I have a templated constructor (based off the STL containers) for a templated class that takes two input iterators. The question is, how do I make sure that the value type of the iterator is the same as the value type of my actual class? Quick example code. [cpp] template<typename _Val> struct Foo { template<typename _InputIter> Foo(_InputIter first, _InputIter last) { //I want to check the value type of the iterators here //If that fails, just throw an exception I guess? } std::list<_Val> data; //Some arbitrary data storage method goes here }; [/cpp][/QUOTE] Correct me if I'm wrong, but I believe [url]http://www.cplusplus.com/reference/std/typeinfo/type_info/[/url] should do the trick.
[QUOTE=Fear_Fox;38102618]Correct me if I'm wrong, but I believe [url]http://www.cplusplus.com/reference/std/typeinfo/type_info/[/url] should do the trick.[/QUOTE] Yeah, I guess it works (preferably using the [URL="http://en.cppreference.com/w/cpp/types/type_info/hash_code"]hash_code[/URL] thing from C++11 because strings can be weird). But what about checking at compile time?
[QUOTE=ECrownofFire;38102670]Yeah, I guess it works (preferably using the [URL="http://en.cppreference.com/w/cpp/types/type_info/hash_code"]hash_code[/URL] thing from C++11 because strings can be weird). But what about checking at compile time?[/QUOTE] [url=http://www.cplusplus.com/reference/std/type_traits/is_same/]is_same[/url]? [editline]19th October 2012[/editline] You could do a static assert instead of throwing an exception.
I think this does the trick, combined with static_assert. [url]http://en.cppreference.com/w/cpp/types/is_same[/url] Ahhh, ninjas. But yes, I think this will do just fine.
I basically need somekind of C# library that makes me able to recognize sounds, I want to recognize my guitar's notes, which are played over the microphone. Can someone help me with this?
Sound recognition is a spectacularly complex subject. I don't think you're going to be able to find libYepThatsAGuitar.
I think the point was he wants to recognise certain frequencies, which would be done via Fourier transforms But I never could figure out how the hell those work
Sorry, you need to Log In to post a reply to this thread.