Simple question about fonts
Author |
Message |
nmr123321
|
Posted: Tue Jan 24, 2006 9:25 pm Post subject: Simple question about fonts |
|
|
code: |
var font1 : int
var fontSize : int
for i : 1 .. 25
font1 := Font.New ("Arial:fontSize:bold")
Font.Draw ("Hello", maxx div 2, maxy div 2, font1, red)
delay (100)
Font.Draw ("Hello", maxx div 2, maxy div 2, font1, white)
fontSize := fontSize + 1
end for
|
Is it possible to replace the size in a Font.New statement with a variable?
any help will be appreciated |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Delos
|
Posted: Tue Jan 24, 2006 9:29 pm Post subject: (No subject) |
|
|
Sure it is. In this case, you've considered 'fontSize' as a string and not a variable.
- "fontSize" vs. fontSize
You'll have to catenate the value of 'fontSize' to the rest of the string.
So, for instance:
code: |
var temp : string := "#"
put "a+temp" %--> a+temp
put "a" + temp %--> a#
|
See the difference?
- type-casts
Right now, you have fontSize as an int. To catenate, you have to have all types the same. You could consider redeclaring fontSize as a string instead, or you could just type-cast it. E.g.
code: |
put 1, " is a number"
put intstr(1) + " is actually a string"
|
See the difference? strint() and intstr() are useful, very (simple, acronymical names, too).
Post up your code when you're done so we can see how well you fared. |
|
|
|
|
|
nmr123321
|
Posted: Tue Jan 24, 2006 9:49 pm Post subject: (No subject) |
|
|
never seen this before, thanks .But do i put this instr(fontSize)+' outside the font statement. I am getting this error
Bad font size'instr(fontSize)+' in font selection string
code: |
var font1 : int
var fontSize : int:=10
for i : 1 .. 10
font1 := Font.New ("Arial:intstr (fontSize)+")
Font.Draw ("Hello", maxx div 2, maxy div 2, font1, red)
delay (100)
Font.Draw ("Hello", maxx div 2, maxy div 2, font1, white)
fontSize := fontSize + 1
end for
|
[/code] |
|
|
|
|
|
Clayton
|
Posted: Wed Jan 25, 2006 8:22 am Post subject: (No subject) |
|
|
you dont put the + after your intstr(fontSize), you put that before instr(fontSize), then close the brackets. see if thats wat your prob is |
|
|
|
|
|
Clayton
|
Posted: Wed Jan 25, 2006 8:23 am Post subject: (No subject) |
|
|
also close the quotes befor your variable otherwise turing wont recognize fontSize as a variable |
|
|
|
|
|
|
|