• Hello everyone,

    We're happy to announce that our forum is back online! We needed to take some time off to discuss and decide on how to handle sensitive topics in our community.

    The team has posted an in-depth comment regarding a recent incident and our stance on politics and sexuality in our forum. We also added a dedicated paragraph about this in the forum guidelines. This is part of our commitment to maintain a welcoming and inclusive environment for all our users. Your understanding and continued support in building a creative and respectful community are highly appreciated.

    Thank you, the CX Dev-Team

Illegal number of arguments for type conversion, using TextWidth


New member
Apr 4, 2023
Hello; this is my first forum post here, please warn me for anything I do wrong.
I'm trying to center a text, by substracting the half of TextWidth from the half of DeviceWidth, but I get an error, called in the title.

Here's how I am trying to do it:

Import mojo2
Import mojo2.graphics

' ...

Global scoreText:String
Global scoreDiment:Int

' ...

        scoreText = String(strings[currentLanguage][0].Replace("ü", score))
        scoreDiment = Font().TextWidth(String(scoreText))
        myCanvas.DrawText(scoreText, DeviceWidth/2-scoreDiment, 0)
(Some ways I do things the way I am used to might be impractical, sorry.)

The reason I used "Font().TextWidth" is because it wont work without calling the Font class. It would work without calling it in mojo (1)

Any help would be appreciated.
Hi, welcome.
Is there a reason why you do type casts all the time?
Is there a reason why you do type casts all the time?
Thanks for your response.
The reason was because I was thinking the error was some sort of Type mismatch, but when I wrote the original code, there were no casts.
I will try it now, thanks again.
Hey Timur, welcome to the forum!
Don't be hesitant to ask questions. There are not too many active users that need help at the moment so you can get an answer pretty quickly and we are happy about every new active member here.
I had a look at your code and noticed two things:
  • You can just import mojo2 without an additional mojo2.graphics. The mojo2 import is a container import that imports all the basic modules for graphics, sound and input you need for a functional app.
  • You can center text horizontally by just setting the xhandle value to 0.5 so the center of your text gets drawn at the chosen position.
Thanks for your response. I will look forward to ask for support here.
Through further investigation of the documentation, I have found out that in fact, mojo2 imports everything, thank you.
I thought handles were only supported on Image classes, but I will center it using the handles from now on. Thanks again.
Top Bottom