• What do you need help with? Version 5
    5,752 replies, posted
But now I have to access it like Entity.getComponent<Size>("size"), whereas I want to just access it like this Entity.getComponent("size").
[QUOTE=WTF Nuke;39484849]But now I have to access it like Entity.getComponent<Size>("size"), whereas I want to just access it like this Entity.getComponent("size").[/QUOTE] Yeah, well I'm pretty sure that's unfortunately not solvable in a pretty way in C++.
You should stay away from accessing your entities from C++ like you would from a mapping perspective. If you want size as member, add it as real member. If you need more, create a subclass. If you need to access them as strings I suggest you use a scripting language with getField/setField functions or overloaded operators.
[QUOTE=WeltEnSTurm;39485085]You should stay away from accessing your entities from C++ like you would from a mapping perspective. If you want size as member, add it as real member. If you need more, create a subclass. If you need to access them as strings I suggest you use a scripting language with getField/setField functions or overloaded operators.[/QUOTE] I am using a component system, so adding it as a real member defeats the whole purpose.
Passing a string to a function and getting an object of any type back defeats the whole purpose of C++
C++ sucks because it expects the coder to specify/know the data type of a piece of data that needs to be manipulated. Knowing data types is so 90s.
[QUOTE=DarkCybo7;39485314]C++ sucks because it expects the coder to specify/know the data type of a piece of data that needs to be manipulated. Knowing data types is so 90s.[/QUOTE] Oh. It's [b]this[/b] shitfest again.
-snip-
My previous post was very serious and should be taken literally.
[QUOTE=DarkCybo7;39485314]C++ sucks because it expects the coder to specify/know the data type of a piece of data that needs to be manipulated. Knowing data types is so 90s.[/QUOTE] yeah stuff that runs 9000x faster than any fully dynamic language is so 90s
[QUOTE=DarkCybo7;39485449]My previous post was very [b]terrible[/b] and should be [b]deleted[/b].[/QUOTE] that's better
[QUOTE=WeltEnSTurm;39485568]yeah stuff that runs 9000x faster than any fully dynamic language is so 90s[/QUOTE] [URL="http://luajit.org/"]Dynamic languages can come [B]very[/B] close to static ones.[/URL]
[QUOTE=WTF Nuke;39484849]But now I have to access it like Entity.getComponent<Size>("size"), whereas I want to just access it like this Entity.getComponent("size").[/QUOTE] You could also do something like this: [code]Size* size; if (Entity.getComponent(size)) { // Size is valid, do shit }[/code] Or something like this [code] Component* component = Entity.getComponent("size") Size* size = static_cast<Size*>(component); // We know which type it is, use dynmic_cast to test it first if unsure [/code]
[QUOTE=lavacano;39485589]that's better[/QUOTE] I use levels of irony that are probably incomprehensible to you.
[QUOTE=Robbis_1;39485706]You could also do something like this: [code]Size* size; if (Entity.getComponent(size)) { // Size is valid, do shit }[/code][/QUOTE] You're passing a reference to a pointer? Never seen that before.
[QUOTE=ArgvCompany;39485733]You never initialize size. Edit: Wait, you're passing a reference to a pointer? Never seen that before.[/QUOTE] Correct, if it returns false you shouldn't use the pointer. You can also do this: [code] if (Size* size = Entity.getComponent<Size>()) { // Size is valid, do shit } [/code]
[QUOTE=Robbis_1;39485706]You could also do something like this: [code]Size* size; if (Entity.getComponent(size)) { // Size is valid, do shit }[/code] Or something like this [code] Component* component = Entity.getComponent("size") Size* size = static_cast<Size*>(component); // We know which type it is, use dynmic_cast to test it first if unsure [/code][/QUOTE] The second solution is the one I wanted to avoid, and the first is solved already with getComponent<Size>() since it gets the first Size rather than going by name.
In all honesty this is a lot of circumventing just to avoid casting a data type or specifying a data type to a template call. It reeks of lazy coding.
Can I engineer this to work? [url]http://stackoverflow.com/questions/1010539/changing-return-type-of-a-function-without-template-specialization-c[/url] [editline]5th February 2013[/editline] [QUOTE=DarkCybo7;39485836]In all honesty this is a lot of circumventing just to avoid casting a data type or specifying a data type to a template call. It reeks of lazy coding.[/QUOTE] Is lazy and more readable code a bad thing or something?
[QUOTE=WTF Nuke;39485869]Can I engineer this to work? [url]http://stackoverflow.com/questions/1010539/changing-return-type-of-a-function-without-template-specialization-c[/url] [editline]5th February 2013[/editline] Is lazy and more readable code a bad thing or something?[/QUOTE] A function that returns multiple data types without the programmer having to specify the data type he wants is something that worries more than having code that is less "readable"
[QUOTE=WTF Nuke;39485869]Is lazy and more readable code a bad thing or something?[/QUOTE] I fail to see how using a component system is readable [editline]5th February 2013[/editline] [QUOTE=DarkCybo7;39485710]I use levels of irony that are probably incomprehensible to you.[/QUOTE] irony inception is gay
[QUOTE=WTF Nuke;39485869] Is lazy and more readable code a bad thing or something?[/QUOTE] Both could be depending on the language. Lazy is more likely to be.
[QUOTE=amcfaggot;39478525][url]https://developer.valvesoftware.com/wiki/Threads[/url][/QUOTE] I'm dumb and didn't check the wiki, ty. Helped me figure out my threading was fine, it's something to do with websockets++ not cleaning up properly, or me not closing it down correctly.
[QUOTE=dajoh;39485599][URL="http://luajit.org/"]Dynamic languages can come [B]very[/B] close to static ones.[/URL][/QUOTE] Oh yeah, LuaJIT is awesome. To add something more to my argument, static typing makes everything safer and more predictable.
If you want it more readable and less lazy you could also make getInt getFloat getString methods that return a specific data type. (if you really hate templates and casting)
I understand the issue of type safety, and I'll just stick to this method.
[QUOTE=WTF Nuke;39485806]The second solution is the one I wanted to avoid, and the first is solved already with getComponent<Size>() since it gets the first Size rather than going by name.[/QUOTE] Right, but the first was an alternative to <Size> if you wanted to avoid having visible template code. So which one did you stick to?
[QUOTE=Robbis_1;39486162]Right, but the first was an alternative to <Size> if you wanted to avoid having visible template code. So which one did you stick to?[/QUOTE] I'm gonna do getComponent<Component>() and if disambiguation is needed, getComponent<Component>(string) Edit: New quick question for people who have used SFML, when writing my render class, should I inherit from renderwindow or just have it as a member?
Quick Python question. How would one go about (if possible) writing a for loop that ends once a condition is met. I'm using a while loop in this code: [code]if stats != 0: print "You have %d points left over." % stats print "You have %d Body and %d Mind." % (body, mind) print "You must spend all your points!" while x != 2: if stats != 0: while x == 1: print "How much do you wish to put into Body?" temp = int(raw_input("> ")) body += temp stats -= temp if ((body <= 3 and body >= 0) and stats >= 0): print "You have %d points in Body!" % body x = 0 else: stats += temp body -= temp print "That's invalid." if stats != 0: while x == 0: print "How much do you wish to put into Mind?" temp = int(raw_input("> ")) mind += temp stats -= temp if ((mind <= 3 and mind >= 0) and stats >= 0): print "You have %d points in Mind!" % mind x = 1 else: stats += temp mind -= temp print "That's invalid." else: x = 2[/code] Basically I just set x = 2 in order to end the loop, but I was wondering if there was a way to do so in a for loop, as I hear it's much better to use when possible. Basically it checks if the user hasn't used all their "stat points", and if so, forces them to put the points into the stats.
I'm trying to pick out a C++ IDE for use on Windows. Am I best to use Visual Studio? I'd like to do some cross-platform stuff, is it going to inhibit code portability if I'm only using portable libraries?
Sorry, you need to Log In to post a reply to this thread.