
-----------------------------------
Shib
Sun Dec 16, 2007 7:21 pm

Procedure that centers text
-----------------------------------
Can somebody please help me write the procedure that centers text? Thanks alot guys.

-----------------------------------
Ultrahex
Sun Dec 16, 2007 7:47 pm

Re: Procedure that centers text
-----------------------------------
Think about how x-coordinates change base on length of the string you are writing in the font you are writing in.

-----------------------------------
Shib
Sun Dec 16, 2007 7:52 pm

RE:Procedure that centers text
-----------------------------------
Do you have the code? it would be easier if you gave it to me and then I could figure out whats going on.

-----------------------------------
Tony
Sun Dec 16, 2007 8:11 pm

RE:Procedure that centers text
-----------------------------------
sure thing.

If you are using plain text, you'll need
length() - length of string
locate() - moving the cursor before the put statement

If you are using graphics text, you'll need
Font.Draw() - obviously to draw the text itself
Font.Width() - to calculate the width of the text string

-----------------------------------
CodeMonkey2000
Sun Dec 16, 2007 8:56 pm

RE:Procedure that centers text
-----------------------------------
We aren't suppose to write code for you. But we can give you advice. Why don't you attempt the problem first?

-----------------------------------
Nick
Sun Dec 16, 2007 9:29 pm

Re: Procedure that centers text
-----------------------------------
Can somebody please help me write the procedure that centers text? Thanks alot guys.

I do think he intends to write it himself just needs some help doing it ;)

think about the length of the text between "Hello world" and "baz bar foo baz bar foo"

-----------------------------------
Euphoracle
Sun Dec 16, 2007 10:56 pm

Re: RE:Procedure that centers text
-----------------------------------
sure thing.

If you are using plain text, you'll need
length() - length of string
locate() - moving the cursor before the put statement

If you are using graphics text, you'll need
Font.Draw() - obviously to draw the text itself
Font.Width() - to calculate the width of the text string

Also,
If you are using plain text, you'll need
maxcol - columns in the "console"
maxrow - rows in the "console"

If you are using graphics text, you'll need
maxx - width of the window
maxy - height of the window

-----------------------------------
Shib
Mon Dec 17, 2007 8:36 am

RE:Procedure that centers text
-----------------------------------
This is what I got so far


procedure centerText
Font.Draw (centerText , maxx div 2, maxy div 4, font, black)
end centerText

cls
centerText ("Loading Please Wait...")
centerText ("Press Anykey to continue")
Input.Pause


it says assignment wrong type :S

-----------------------------------
Carey
Mon Dec 17, 2007 10:58 am

RE:Procedure that centers text
-----------------------------------
take a closer look at what you're doing. You're drawing a procedure and that wont work, hence error. What you want to do is find the width of the string using Font.Width(), divide it by 2 and subtract that amount from the x coord. You will probobly want to also structure your procedure like so:


procedure centerText (text :string, x, y :int)
   %draw the text here
end centerText


you would then call the procedure like this:

centerText ("Centered text :)", 200, 200)


this will draw "Centered text :)" at 200 over and 200 up (x, y)
