PDA

View Full Version : Calling the Lscript God that is faulknermano!



Matt
11-27-2003, 03:56 PM
Hi!

Yes, me again with another dumb question!

I've check the docs (Chapter 1 : Common Commands) hoping to find the answer, but alas no luck!

- - -

How do I fill in a number (X) with leading zeros up to the units of a specified total?

Examples:

if total = 100 and X=6
How can I re-format (as a string) X so that it becomes 006

if total = 100 and X=99
How can I re-format (as a string) X so that it becomes 099

if total = 10 and X=2
How can I re-format (as a string) X so that it becomes 02

if total = 1000 and X=75
How can I re-format (as a string) X so that it becomes 0075

etc. (hope that made sense!)

Essentially I want my script to 'smart rename' rather than making the user specifying the units.

The script renames polygon surfaces, so if there were 1246 polygons selected and I wanted them renaming to surface_0001, surface_0002, surface_0003 rather than surface_1, surface_2, surface_3 which is how it works now.

- - -

Oh something else before I forget.

When using ctlrefresh(); in a callback can you refresh more than one gadget at a time? My script will only refresh one gadget, even if I have unique callback procedures.

As always your help is very much appreciated!

Cheers
Matt

P.S. I've been bitten by the LScript bug here!!! :)

WizCraker
11-27-2003, 04:27 PM
Hey Matt have you tried joing the LScript mailing list they are some great guys that answer the questions like this pretty quick.

corwin
11-27-2003, 07:38 PM
Objectsaver: basesavefile, startingframenumber, savenumber

{

addsavenumber = savenumber + startingframenumber;
savenumberstring = string(addsavenumber);
sizesavenumber = size(savenumberstring);
zerostring = "";
for( i = 1; i <= (4 - sizesavenumber); i++)
{
zerostring = zerostring + "0";
}
fourdigits = zerostring + savenumberstring;
cropsize = size(basesavefile) - 4;
savefilename = strsub(basesavefile,1,cropsize) + fourdigits + ".lwo";
save(savefilename);
}



you could modify this objectsaver code slightly: substitute the 4 in the for loop with the size( totalnumber), then fourdigits (now not necessarily 4) would be of the correct size!

Jabba
11-28-2003, 02:51 PM
Originally posted by Matt
Hi!

if total = 100 and X=6
How can I re-format (as a string) X so that it becomes 006

if total = 10 and X=2
How can I re-format (as a string) X so that it becomes 02

if total = 1000 and X=75
How can I re-format (as a string) X so that it becomes 0075



X = 6;
Total = 125;
If ( total < 10000 ) A = Name.asStr(4,true);
If ( total < 1000 ) A = Name.asStr(3,true);
If ( total < 100 ) A = Name.asStr(2,true);

... variable (string) "Name" will be "006"

faulknermano
12-02-2003, 09:31 AM
hey matt, the thread name is kinda embarrassing. :)

jabba's code is cool.. here's a mod of it:



generic
{
x = 1000;
xs = string(x);
digits = xs.size();

for(i=1;i<=x;i++)
{
name = i;
a = name.asStr(digits,true);
... // do what you want with the variable a
}

}

Matt
12-26-2003, 08:58 AM
Ahhh, thanks faulk! sorry, didn't mean to embarrass you! :)

I must be learning, I had the same idea, rather than use real numbers, turn it into a string and count the length, much easier!

Thanks!

:)