[Closed] Formatted print
Hi Gents I am having a hard time with the formatted print syntax , a simple example I wanted to count in a loop using padded numbers 001 – 012 etc . The dfault loop counts 1 2 3 4 , etc .
ie
for i = 1 to 10 do print i
this counts as per standard.
for i = 1 to 10 do
(
formattedPrint i format:"03d"
print i
)
returns still 1 2 3 4 5 6 etc ,
can anyone explain where I am going wrong in my approach ?
b
The formatdedPrint syntax is:
[i]
formattedPrint[/i] <value> [i]format[/i]:<string>
You have missed the <value> that have to be printed
But I can’t understand what exactly you want to do. 001 and 012 are not real numbers. 1 and 12 are. What is the problem to loop from 1 to 12 and not from 001 to 012?
I have a set of files numbered 001 to 022 , I am using a loop to cont through each file and assign it to a material dif slot ,
so file 004 goes into material number 4 dif slot . i represents the count so as you can imagine I use i to replace the value in the string path. My current script looks like this
for i = 07 to 011 do
(
newmat = VRayMtl()
newmat.name = ("m_con_type_" + i as string)
newmat.texmap_diffuse = Bitmaptexture fileName:(@"\\blah\foo\dave\foobar\JPEG\concrete-00" + i as string + "_d100.jpg")
)
It works until you get to a number greater than 9 when padding kicks in. I have revised my example above to this
for i = 1 to 10 do
(
formattedPrint i format:"03d"
print i
)
Still this prints as 1 2 3 4 5 6 and I dont get padding
b
So digging further and looking at examples
for i = 0 to 10 do
format "%
" (formattedPrint i format:"03d")
gives me 000 , 001 etc . I am still unsure as to the difference between format and print if I print i it returns 10 . Maybe my whole approach is wrong !
It indeed is, you were printing ‘i’, not the result of formattedPrint. It would work the same way with print (formattedPrint i format:“03d”)