Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / [SOLVED] trying to change text color mid text command, darkbasic is outputting errors no matter what i try

Author
Message
festivneer
2
Years of Service
User Offline
Joined: 18th Aug 2021
Location:
Posted: 18th Aug 2021 15:06
kinda said it in the title, im trying to do something along the lines of:

text 50, 50, "first part"+ INK RGB (0,255,0), RGB (0,0,0) +"second part"

but no matter what form of that i try i always get some kind of error.
any solution to this or am i going to have to manually make a new text command and put the word exactly at the spot it should be?

The author of this post has marked a post as an answer.

Go to answer

Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 18th Aug 2021 23:50
I would normally do something like this....


ink rgb(100,100,100)
a$="first part ":t=text width(a$)
text 50, 50,a$: INK RGB (0,255,0), RGB (0,0,0):text 50+t,50,"second part"

do

sync
loop
festivneer
2
Years of Service
User Offline
Joined: 18th Aug 2021
Location:
Posted: 19th Aug 2021 01:14
while it does work, id prefer something that does not use a extra string and optimally is contained to one line, as im going to be doing this a lot.
Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 19th Aug 2021 05:05
This post has been marked by the post author as the answer.
In that case it is usual to make a subroutine or function supplied maybe with a string and position data
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 19th Aug 2021 13:12
So the way that the Print / Text Commands work., is that they will use the colour set by the Ink command until you next use the command.
As such if you want to output different colours, you HAVE to break up the output string into the colours you want.

Of course what we can do is instead of printing using the Text command the entire String; we instead can output the individual letters.

i.e.


You don't loose the original String as you can see., but we can still have some fun with the output.
And as we have the TextWidth as a value; we can essentially use the Int( Mouse Position / Text Width ) to then return the Letter Position; so let's say we want to have something similar to Hyperlinks.



This is a crude example., but with some time and effort you can refine all of this with Types, Arrays and Functions.
It should give you a good starting point though.
Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 22nd Aug 2021 02:57
or you could use the print command,

print "first part ";
ink rgb(200,20,20):print "second part"

sync
sync
wait key

but then you'd need to use set cursor....
Code Maker
8
Years of Service
User Offline
Joined: 4th Dec 2015
Location:
Posted: 22nd Aug 2021 20:59
I would use a function aka create my own command like this


The mytext function parameters is as follows
text$ = the text you want to print
xpos = horisontal position of the text (if set to -1 it will bee output in continuation of the last text)
ypos = vertical position of the text
red = red color value of the text
green = green color value of the text
blue = blue color value of the text
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 24th Aug 2021 11:03
This is all a bad way to handle this problem. You will likely end up with a huge amount of hard coded text positions, and a good possibility the program looks different on other computers. Particularly if the resolution or font changes in any way.

What you need is support for inline color codes. That is to say a function that will accept the string with color codes in the string, that way its all just a simple reusable function call.

I wrote this a while back now it may be helpful:
https://forum.thegamecreators.com/thread/220759

Mages Modular Code is a DBA you can #include to any existing program and it gives some graphical UI functionality. Particularly 'MFont'.


Mfont is a bitmap font implementation and it supports inline color codes.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 24th Aug 2021 11:14
This would be the entire example using MFont:

MInit()
MFont_InlineColor_Enable()
MFont_Text(50, 50, "{00FF00}first part{0000FF}second part{}")

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!

Login to post a reply

Server time is: 2024-04-19 11:18:54
Your offset time is: 2024-04-19 11:18:54