Well, in a GTA game I have been making a little over a year now. There is a label on the interface. This label serves many perpousus.. One is to show you how much money you have, two is to show you how much Mall Money you have, and three is to show you how much HP/MaxHP the person you are attacking has..... You would think it would be simple to get the text for this right??? Well, check out the ordeal I went through for about 20 minutes... At one point I was just randomly placing ]" :p.....
var/texts = " Money: $[num2text(usr.money,50)][usr.mall>0?" Mall Money: $[num2text(usr.mallmoney,50)]":""][usr.lastatt!=null?" [usr.lastatt:name]'s hp: [usr.lastatt:incar == 1 ? "[usr.lastatt:carhp]/[usr.lastatt:car != null ? "[usr.lastatt:car:maxhp]" : "[usr.lastatt:maxhp]"]" : "[usr.lastatt:hp]/[usr.lastatt:maxhp]"]" : ""]"
Anywho, I find it very saddening when even something as simple as text can confuse a non-amature(non-pro ^-^) coder........... Im obviously not the best... But come-on!!! It's just text for cryin out loud ^_^!!!!
ID:45421
![]() Jul 17 2008, 8:36 am
|
|||||||||||||
Poll: Do you even understand the code given below?
Login to vote.
|
DivineO'peanut wrote:
There's nothing sad about it. Your code is terrible and confusing (no offense intended). I don't blame the programmer. How exactly is my code "terrible" and "confusing".... I was trying to use a method cosidered better... The whole [usr.var==whatever ? "" : ""] way... :(!!!!!! |
DivineO'peanut wrote:
There's nothing sad about it. Your code is terrible and confusing (no offense intended). I don't blame the programmer. This. Good try at being an elitist though. |
K'ros Trikare wrote:
DivineO'peanut wrote: I don't care about being/appear to be an elitist... Just the code is more advanced then using a CRAP load of if's... Also, it's easier to do it that way then using a bunch of if's.... |
That looks like very newbish code to me, especially given the classic mistakes of abusing ':', 'usr' and 'var == 1' all over the place.
In my mind, the two things that make a programmer stand out as being good at what they do, aside from being efficiency freaks, is that 1) They don't have trouble making programs that do what they want, and 2) Their code is easy to understand. My way might not be the best, but in my mind something like this, instead of using a bunch of embedded if statements all crammed into one huge text string, might work this way: mob/proc/UpdateStatLabel() var/label = "" if(src.money) label += "Money: $[num2text(src.money, 50)] " if(src.mall_money) label += "Mall Money: $[num2text(src.mall_money, 50)] " if(src.lastatt) .. However, beyond that point I think its simply just poor design. I can't understand why a mob would have an "incar" variable that's true, while having a "car" variable that's null. Why aren't you just checking to see if the mob has a non-null "car" value in the first place, and totally get rid of the "incar" variable? Whatever the case, if everything were done right, I'd probably write it to look like this: // This updates the player's status label to include their // current money (if any), mall money (if any), and if the // player was recently attacked, it displays the health of // the enemy who attacked the player last, or if the enemy // was in a car, it will display the health of the car. mob/proc/UpdateStatLabel() var/label = "" if(src.money) label += "Money: $[num2text(src.money, 50)] " if(src.mall_money) label += "Mall Money: $[num2text(src.mall_money, 50)] " // Display the health of the last enemy to attack the player: if(src.lastatt) // If the last attacker has a car, display the car's health: if(src.lastatt.car) label += "[src.lastatt.name]'s HP: [src.lastatt.car.hp]/[src.lastatt.car.maxhp]" // Otherwise, display the attack's health. else label += "[src.lastatt.name]'s HP: [src.lastatt.hp]/[src.lastatt.maxhp]" winset(src, "window.label", "text=\"[label]\"") return Even though that looks terrible because blog comments don't support code. Bleh. |
Ss4toby wrote:
Just the code is more advanced then using a CRAP load of if's... Also, it's easier to do it that way then using a bunch of if's.... Compare my code to your code and tell me which is "easier". Ifs aren't bad. Embedded ifs have their place, but they're not necessarily better. Better to have code that takes to 30 seconds to figure out than 20 minutes. |
Foomer wrote:
That looks like very newbish code to me, especially given the classic mistakes of abusing ':', 'usr' and 'var == 1' all over the place. Honestly, your right about the whole in-car thing.... I kinda crapply made the car system to were there are cars that go off the carhp variable, and cars that go off hp... Anywho, I have one kinda good question... Why exactly should I have to explain everything if Im going to be the only one to look at it? I know this-time has been an exception because I posted it... However, normally my codes are basicly for my eyes only... No point in explaining stuff to myself =)... Right >.<? |
Nadrew wrote:
There's no : abuse there Foomer. He's using embedded conditionals. YOU SHUT UP!!! Toby defends Toby!!! I don't need you sugar daddy.... |
Firstly, if you're going to post code, use the <dm> tags. Secondly, that code is ugly.
|
Foomer wrote:
usr.lastatt:name What about it??? The variable usr.lastatt = an mob.... So to find that mob's name ya gotta do it usr.lastatt:name... Or are you saying I could just put usr.lastatt =D... I never do that to define someone's name... Enless it's just [usr] or [m]... Etc.. |
Foomer wrote:
Why do you need to defend anything? This isn't a fight or an argument. Im just jacking around.... Im bored... I find it fun to be constantly on the offence but never offended... |
Popisfizzy wrote:
Firstly, if you're going to post code, use the <dm> tags. Secondly, that code is ugly. I wish I could ban people like you from posting on my blog... I'll find a way... You just wait!! Pluss!! Look at my picture!! Do you see that face? Does that look like the face of someone who cares about what Popisfizzy thinks!?!?! |
Ss4toby wrote:
What about it??? The variable usr.lastatt = an mob.... So to find that mob's name ya gotta do it usr.lastatt:name... Or are you saying I could just put usr.lastatt =D... I never do that to define someone's name... Enless it's just [usr] or [m]... Etc.. No, you need to define those values correctly. You also should avoid using usr, especially if it's in a proc. As Foomer stated, you have : abuse, usr abuse, and failure at using boolean logic, and all of that is coming out the ass. It's pretty bad. |
Ss4toby wrote:
I have one kinda good question... Why exactly should I have to explain everything if Im going to be the only one to look at it? And that right there is a classic beginner's question. It apparently takes a while to figure out, but eventually you'll realize that when you spend time making your code as clean and readable as possible, you're making things easier on yourself when you come back to update them or work with them later. It makes bug hunting infinitely easier, too. Plus, if you get to the point where you can clean up your code enough that you can build everything as modules, then you can start porting your code from project to project with minimal effort, and that saves you tons of time. But the bottom line is that its for your own benefit in the long run to make your code clean and readable. Providing comments helps a lot, too, because sometimes you can read what you wrote about a function and it will help you to understand why you did something in a certain way. I'm sure there's some better answers for this question than the one I gave, but I can't find them at the moment. |
Popisfizzy wrote:
Ss4toby wrote: Boolean logic?... Well, as for the other stuff... My codes work. I use usr where I can and only use src if needed...... Im a self taught coder... I was too lazy to read and too ingorent to think... If it works I use it. If it doesn't I fix it... That simple. |
Also, code = text.