Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Retardating scripts, one at a time (https://forums.graalonline.com/forums/showthread.php?t=70600)

Yen 12-04-2006 11:44 PM

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;



Admins 12-05-2006 01:36 AM

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 ;)

coreys 12-05-2006 01:45 AM

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...

Gambet 12-05-2006 03:15 AM

Quote:

Originally Posted by Stefan (Post 1250289)
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.

Yen 12-05-2006 03:24 AM

Down with format!

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

coreys 12-05-2006 05:01 AM

Quote:

Originally Posted by Yen (Post 1250338)
Down with format!

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

hax! ;(

xAndrewx 12-05-2006 09:40 AM

format(_("%"), ee)
kicks ass

Skyld 12-05-2006 10:18 AM

Quote:

Originally Posted by Gambet (Post 1250334)
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.

Admins 12-05-2006 12:22 PM

Probably was a joke :D

Twinny 12-05-2006 03:28 PM

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 ^^

xAndrewx 12-05-2006 08:34 PM

Quote:

Originally Posted by Skyld (Post 1250435)
It has much practical use and it is certainly not a waste of time.

Hell yeh! ;)

Gambet 12-05-2006 10:13 PM

Quote:

Originally Posted by Skyld (Post 1250435)
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.

Skyld 12-05-2006 10:33 PM

Quote:

Originally Posted by Gambet (Post 1250561)
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.

Gambet 12-05-2006 10:46 PM

Quote:

Originally Posted by Skyld (Post 1250569)
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.

Admins 12-06-2006 12:23 AM

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.


All times are GMT +2. The time now is 11:51 PM.

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