• Changing Vectors into Strings
    12 replies, posted
Can Anyone Tell me how can I change Vectors into Strings? Because I'd like to print a message with shown vectors - here is the code: (of course EX2) [code] @name NPC Finder @persist NPC:entity runOnTick(1) POS = NPC:pos() A = owner():lastSaid() EntityPos = entity():pos() if(A=="find") { findByClass("npc_*") NPC = findClosest(EntityPos) print(POS) } [/code] And i get error - cant print vectors.... If you see some other mistakes here please tell :)
print(POS:toString()) [code] @name NPC Finder @persist NPC:entity O:entity if (first()) { runOnTick(1) runOnChat(1) O = owner() } if (chatClk(O)) { A = O:lastSaid() EntityPos = entity():pos() if(A:lower()=="find") { findByClass("npc_*") NPC = findClosest(EntityPos) print(POS) } if (NPC) {POS = NPC:pos()} [/code]
The wiremod developers really did mince Lua when creating E2. It should really be tostring(vector) without the dumb capitalisation thing.
As far as I know, both can be done. From E2helper: String=toString(vector v) String=vector:toString()
[QUOTE=whosdr;22907899]As far as I know, both can be done.[/QUOTE] What I commented on was the fact they changed it to toString which looks fuck ugly. I like good looking code.
toString is easier to read as singular words, which helps to explain what it does.
[QUOTE=whosdr;22906322]print(POS:toString()) [code] @name NPC Finder @persist NPC:entity O:entity if (first()) { runOnTick(1) runOnChat(1) O = owner() } if (chatClk(O)) { A = O:lastSaid() EntityPos = entity():pos() if(A:lower()=="find") { findByClass("npc_*") NPC = findClosest(EntityPos) print(POS) } if (NPC) {POS = NPC:pos()} [/code][/QUOTE] Well, code editor finds an Error about missing bracket, which isn't missing but like always with these errors... So could u check it and tell me wheres a mistake, cuz i cant find it.. BTW my code is OK :) it works, but one problem - how to make it show the position only once, just when i type find and repeat it when I type find again? One more: I get script error when closest NPC is killed - why??
Oh, sorry. [code] @name NPC Finder @persist NPC:entity O:entity if (first()) { runOnTick(1) runOnChat(1) O = owner() } EntityPos = entity():pos() if (chatClk(O)) { A = O:lastSaid() if(A:lower()=="find") { findByClass("npc_*") NPC = findClosest(EntityPos) print(POS) } } if (NPC) {POS = NPC:pos()} [/code]
[QUOTE=whosdr;22908102]Oh, sorry. [code] @name NPC Finder @persist NPC:entity O:entity if (first()) { runOnTick(1) runOnChat(1) O = owner() } EntityPos = entity():pos() if (NPC) {POS = NPC:pos():toString()} if (chatClk(O)) { A = O:lastSaid() if(A:lower()=="find") { findByClass("npc_*") NPC = findClosest(EntityPos) print(POS) } } [/code][/QUOTE] Corrected it, now works well :) The problem was, you defined POS after printing it, you also forgot to turn it into string :) BTW, could you explain me this part of code: [code] if (chatClk(O)) { A = O:lastSaid() if(A:lower()=="find") { } } [/code]
[QUOTE=|FlapJack|;22907911]What I commented on was the fact they changed it to toString which looks fuck ugly. I like good looking code.[/QUOTE] Your tastes differ from mine. tostring makes me wanna barf. toString is hawt, so is ToString (but due to E2's syntactical limitations we can't have ToString as a func name) Which looks better to you: somevectorfunc() or someVectorFunc()? Or maybe SomeVectorFunc()?
[code] if (chatClk(O)) { #Only runs when you say something A = O:lastSaid() if(A:lower()=="find") { #Lowers the text so stuff like FINd works } } [/code]
[QUOTE=whosdr;22917636][code] if (chatClk(O)) { #Only runs when you say something A = O:lastSaid() if(A:lower()=="find") { #Lowers the text so stuff like FINd works } } [/code][/QUOTE] OK, thanks. And one more : How can I use ApplyForce() to make an objecto go to X and Y position but float over destination (with a constant Z)
[QUOTE=lavacano;22916157]Your tastes differ from mine. tostring makes me wanna barf. toString is hawt, so is ToString (but due to E2's syntactical limitations we can't have ToString as a func name) Which looks better to you: somevectorfunc() or someVectorFunc()? Or maybe SomeVectorFunc()?[/QUOTE] Variable names should either be fully upper case, fully lower case or lower and upper case (toString) Methods should be in uppercase for the first letter of each word, lowercase for all others. Vector:ToString() tostring(vector) toString(vector) are all acceptable in my view.
Sorry, you need to Log In to post a reply to this thread.