Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-04-2006, 11:44 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Retardating scripts, one at a time

Is retardating a word? Let's assume it is.

Just thought I'd share this script I made to convert decimal to hexadecimal, as an example of how retarded I can be.
I don't even know what I was doing, or why I was doing it. Then I looked at it and went '... Oh my god.' and created the latter.

PHP Code:
function math_DecToHex(decv) {
  
temp.hex "0123456789ABCDEF";
  
temp.places int(log(16,decv));
  
temp.total decv;
  for (
temp.temp.placestemp.>= 0temp.h--) {
    
temp.subtract int(temp.total/(16^temp.h));
    if (
temp.total 16^temp.h) continue;
    
temp.newvalue temp.subtract;
    
temp.total -= temp.subtract * (16^temp.h);
    
temp.toreturn @= temp.hex.substring(temp.subtract,1);
  }
  return 
temp.toreturn;

PHP Code:
function math_DecToHex(decv) {
  
temp.hex "0123456789ABCDEF";
  
temp.total decv;
  while (
int(temp.total) > 0) {
    
temp.toreturn temp.hex.substring(temp.total%16,1) @ temp.toreturn;
    
temp.total int(temp.total/16);
  }
  return 
temp.toreturn;

Reply With Quote
  #2  
Old 12-05-2006, 01:36 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
You mean you want to show how to optimize / simplify scripts?
Although in this example it would be simpliest to do format("%X",decv) I guess
Reply With Quote
  #3  
Old 12-05-2006, 01:45 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Cool, although (I'll probably seem stupid saying this lol) but what use could you use it for? Unless you're just curious to know what a decimal is in hexadecimal value...or for hex editing...
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #4  
Old 12-05-2006, 03:15 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Stefan View Post
You mean you want to show how to optimize / simplify scripts?
Although in this example it would be simpliest to do format("%X",decv) I guess

format() has no practical use. Not to mention it's a waste of time.
Reply With Quote
  #5  
Old 12-05-2006, 03:24 AM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Down with format!

Yes, I made it mainly for hex editting. It's too much trouble to handle conversions with Window's calculator.
Reply With Quote
  #6  
Old 12-05-2006, 05:01 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Yen View Post
Down with format!

Yes, I made it mainly for hex editting. It's too much trouble to handle conversions with Window's calculator.
hax! ;(
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #7  
Old 12-05-2006, 09:40 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
format(_("%"), ee)
kicks ass
__________________
Reply With Quote
  #8  
Old 12-05-2006, 10:18 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Gambet View Post
format() has no practical use. Not to mention it's a waste of time.
It has much practical use and it is certainly not a waste of time.
__________________
Skyld
Reply With Quote
  #9  
Old 12-05-2006, 12:22 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Probably was a joke
Reply With Quote
  #10  
Old 12-05-2006, 03:28 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
I'd use format() but my powers of pure laziness prevent me from learning how to use it... or achieve any actual development.....meh

Development hell sucks
Reply With Quote
  #11  
Old 12-05-2006, 08:34 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Skyld View Post
It has much practical use and it is certainly not a waste of time.
Hell yeh!
__________________
Reply With Quote
  #12  
Old 12-05-2006, 10:13 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Skyld View Post
It has much practical use and it is certainly not a waste of time.


How is it anymore useful than using @'s, SPCs, etc? It's not very practical besides for using to shorten the length of some lines of code. It all depends on personal style, since you can argue that either is easier to read.

Personally, I find it faster to not use format. If you misplace things while using format, then the outcome won't be that of which you intended, thus making you pay extra attention to where you place things in order for it to work correctly. It's more of a hassle for something that has no real practical use. You get the same outcome in the end.

It's not a matter of efficiency, it's a matter of personal choice, thus, making it less practical than you make it to be. Format() was created to simplify code, yet, it's much more of a hassle than simple writing the whole thing out. And, as I stated before, it's not really easier to read considering the fact that if you don't know how to use format, you wouldn't understand anything that that specific line of code was supposed to do.

It can be argued either way.
Reply With Quote
  #13  
Old 12-05-2006, 10:33 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Gambet View Post
How is it anymore useful than using @'s, SPCs, etc? It's not very practical besides for using to shorten the length of some lines of code. It all depends on personal style, since you can argue that either is easier to read.

Personally, I find it faster to not use format. If you misplace things while using format, then the outcome won't be that of which you intended, thus making you pay extra attention to where you place things in order for it to work correctly. It's more of a hassle for something that has no real practical use. You get the same outcome in the end.

It's not a matter of efficiency, it's a matter of personal choice, thus, making it less practical than you make it to be. Format() was created to simplify code, yet, it's much more of a hassle than simple writing the whole thing out. And, as I stated before, it's not really easier to read considering the fact that if you don't know how to use format, you wouldn't understand anything that that specific line of code was supposed to do.

It can be argued either way.
PHP Code:
temp.foo "My " temp.animal " is eating my " temp.food " quite " temp.speed "! I am " temp.emotion "!"
PHP Code:
temp.foo format("My %s is eating my %s quite %s! I am %s!"temp.animaltemp.foodtemp.speedtemp.emotion); 
I know which I would prefer to edit if I had to.
__________________
Skyld
Reply With Quote
  #14  
Old 12-05-2006, 10:46 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Skyld View Post
I know which I would prefer to edit if I had to.

Exactly my point, it's all based on personal preference.

In the end, it's the same thing, just one contains a shorter length than the other, but it could be easier for one to edit a line that wasn't using format, rather, @'s and so forth.


Format() is fine, it's just not very practical when it wouldn't effect your script efficiency wise if you use it or not.
Reply With Quote
  #15  
Old 12-06-2006, 12:23 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Format-strings can be quite hard to read when you have many %s and %d and %+3d and stuff in it, although I often prefer it since it makes it easier for the translation system.
Reply With Quote
  #16  
Old 12-06-2006, 12:34 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Stefan View Post
Format-strings can be quite hard to read when you have many %s and %d and %+3d and stuff in it, although I often prefer it since it makes it easier for the translation system.


Yeah, and it would confuse the heck out of someone that didn't know what %s, %d, and/or %+3d meant. At least when you write it out the 'longer' way, one can pretty much assume what that line of code is supposed to do based on the fact that it's fully written out and people would be able to use context clues to put two and two together.
Reply With Quote
  #17  
Old 12-06-2006, 01:45 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Gambet View Post
Yeah, and it would confuse the heck out of someone that didn't know what %s, %d, and/or %+3d meant.
Well, if they understand the rest of my script, chances are they are smart enough to look up what format() does. Also, anyone who has ever read the first chapter of a tutorial on C and probably half of those who read tutorials about C++ know how printf works. Other than that while obviously it is a good thing to not intentionally obfuscate scripts, dumbing scripts down other than for learning purposes is not really something I can get behind.

Quote:
At least when you write it out the 'longer' way, one can pretty much assume what that line of code is supposed to do based on the fact that it's fully written out and people would be able to use context clues to put two and two together.
"Hey, look, a bunch of text with apparently magical symbols that do seem to occur in grammatically interesting places, and a bunch of variables afterwards, and the function is called format, I wonder whether these could be placeholders used to format these variables into the text, and if I am not sure I can still check the documentation!" is close enough for me.

Also if I was not totally ignorant of people who do not bother to learn English yet play on an English server, I would agree with Stefan about the localisation issue because translating lots of string fragments with no obvious logical connection and without the ability to reorder the inserted variables to conform to the target language's grammar gets old really fast.


Apart from that, the whole integer formatting part of format is probably way more powerful than equivalent string concatenation magic. And did anyone ever benchmark format applications against equivalent string concatenations?
Reply With Quote
  #18  
Old 12-06-2006, 02:10 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Loriel View Post
Well, if they understand the rest of my script, chances are they are smart enough to look up what format() does. Also, anyone who has ever read the first chapter of a tutorial on C and probably half of those who read tutorials about C++ know how printf works. Other than that while obviously it is a good thing to not intentionally obfuscate scripts, dumbing scripts down other than for learning purposes is not really something I can get behind.

How is it dumbing the script down? There is no difference efficiency-wise. No extra lag is caused, or anything that would be a problem. It's simply a different way of writing it.


Quote:
Originally Posted by Loriel View Post
Apart from that, the whole integer formatting part of format is probably way more powerful than equivalent string concatenation magic.

How is it more powerful in GScript? It's the same thing. It's not "magic," Stefan made it work like that, thus showing that both ways are acceptable. It's all based on personal preference.
Reply With Quote
  #19  
Old 12-06-2006, 02:32 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Gambet View Post
How is it dumbing the script down? There is no difference efficiency-wise. No extra lag is caused, or anything that would be a problem. It's simply a different way of writing it.
My point is that format() is often a superior way of writing it:

Quote:
How is it more powerful in GScript? It's the same thing. It's not "magic," Stefan made it work like that, thus showing that both ways are acceptable. It's all based on personal preference.
So how do you print, using string concatenation, an integer in base 8 padded with zeros to a lenght of 8 characters with a sign character in front? How about a float in decimal notation with 4 digits after the decimal point and grouped by thousands with , between them assuming the locale defines that as thousands grouping character?

Further, how about printing the current date either in yy/mm/dd or dd.mm.yy notation based on some internationalisation setting? Are you going to give your translators a bunch of code to edit and then reinsert into your NPCs with if-statements separating the supported languages?
Reply With Quote
  #20  
Old 12-06-2006, 02:34 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Sheesh, Gambet. What is this the 4352356245626th argument you've started in your life?
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #21  
Old 12-06-2006, 02:42 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Loriel View Post
Stuff

What does this have to do with GScript? My arguments support its function on GScript, considering that's the language that we code in on Graal.

Last edited by Gambet; 12-06-2006 at 02:58 AM..
Reply With Quote
  #22  
Old 12-06-2006, 03:10 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Gambet View Post
What does this have to do with GScript? My arguments support its function on GScript, considering that's the language that we code in on Graal.
I am talking about gscript...?
Reply With Quote
  #23  
Old 12-06-2006, 03:16 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Loriel View Post
I am talking about gscript...?

How does printing apply to Graal? I probably just misunderstood you.

I don't see how there would ever be an instance where you would need to use format.

Don't get me wrong, format looks a lot more clean, but it just doesn't seem very practical to me, and I'm not the only scripter that thinks this. If there's no point on using it, why use it? Just to make the script seem less cluttered? I guess it depends on what you would consider to be cluttered.


Enlighten me.
Reply With Quote
  #24  
Old 12-06-2006, 03:27 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Gambet View Post
How does printing apply to Graal? I probably just misunderstood you.
Oh, I mean printing as in outputting text. To chat or RC or strings or whatever.

Quote:
If there's no point on using it, why use it?
I just keep listing reasons to use it, where it is way more elegant, compact and readable than string concatenation. Someone would need to benchmark it, but chances are it is more efficient too.
Reply With Quote
  #25  
Old 12-06-2006, 03:33 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Loriel View Post
I just keep listing reasons to use it, where it is way more elegant, compact and readable than string concatenation. Someone would need to benchmark it, but chances are it is more efficient too.

But that's exactly what I've said.

It just looks more clean, or 'elegant' as you say. But it makes no difference efficiency wise, which is really what counts. You could argue that format makes script more presentable, but one who prefers to read the elongated version would argue with you.

If there were a clear distinction between the two methods, besides not wanting to format via symbol concatenation, then I would agree that it would be best to use format.
Reply With Quote
  #26  
Old 12-06-2006, 03:45 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Gambet View Post
But that's exactly what I've said.

It just looks more clean, or 'elegant' as you say. But it makes no difference efficiency wise, which is really what counts.
Not at all. See assembly language versus highlevel languages. Programmer time is more expensive than processor time.

Arguing whether efficiency is the most important criterium is for another thread so I will leave now
Reply With Quote
  #27  
Old 12-06-2006, 03:53 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Loriel View Post
Not at all. See assembly language versus highlevel languages. Programmer time is more expensive than processor time.


Considering I hardly ever use format(), I can say that concatenation symbols work a lot faster for me
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.