Source language: Translate to:

writing multicolor strings wherever

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Postby HPW » Thu Mar 08, 2007 12:16 am

You may use the article object with a txt-file with a content-variable.
The you use a monospaced font (all letter use the same width).
Then you have to format the content with spaces to emulate the positioning.

Here are some links using the color:

http://www.neosoftware.com/forum/viewto ... olored+txt

http://www.neosoftware.com/forum/viewtopic.php?t=8329

http://www.software-zone.com/neosoft/in ... e0a7734a97

Or a web-object with a dynamicly created HTML.
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby HPW » Thu Mar 08, 2007 12:20 am

Another option would be to make 80x25 text objects (emulating a DOS screen resolution) for only one monospaced letter.

Then your code writes each letter to its own object and set the color with 'SetObjectFont'.

:wink:
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby Gaev » Thu Mar 08, 2007 5:13 pm

stevor:
Thanks for the info, but sometimes I want to also include a variable in the middle of the text. I'm writing a program to teach math and I want to be able to put something as "How much is ";FirstNum;" + ";SecondNum; when "FirstNum" and "SecondNum" are variables, so I can't just use a text editor to display them.

I think you misunderstood the comment in one of the posts ...You may use the following formatting codes when creating an article with your ASCII text editor ... yes, all you need is an ASCII Text Editor (like notepad.exe) ... but only if you were hand crafting your colored text ... however, you can just as easily create the required text via NeoBook script ... write it to a .txt file ... and then have it displayed in an Article object ... e.g.
Code: Select all
SetVar "[ColoredText]" "^P0How much is ^p^P9[FirstNum]^p ^P2[SecondNum]^p"
FileWrite "[PubDir]myColoredText.txt" "All" "[ColoredText]"
RefreshObject "Article1"

... assuming ...

[FirstNum] was 378
[SecondNum] was 44

... you would see displayed ...

How much is 378 44

... note that ... ^P0 is code for black ... ^P9 is code for red ... ^P2 is code for green.

You can make life easier for your self by assigning meaningful variable names to the codes in your Startup section ...
Code: Select all
SetVar "[inBlack]" "^P0"
SetVar "[inGreen]" "^P2"
SetVar "[inRed]" "^P9"
SetVar "[endColor]" "^p
etc.
... and then do something like ...
Code: Select all
SetVar "[ColoredText]" "[inBlack]How much is [endColor][inRed][FirstNum][endColor] [inGreen][SecondNum][endColor]"
FileWrite "[PubDir]myColoredText.txt" "All" "[ColoredText]"
RefreshObject "Article1"



But as others have mentioned in previous posts ... you are best off using a Browser Object ... and composing your needed text using <html> tags in string variables ... and displaying the contents of such variables in the Browser object ... you get a lot more versatility in the styles you can deploy with <html>.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Gaev » Thu Mar 08, 2007 9:02 pm

stevor:

You do NOT need to use BrowserExecScript in order to populate a Browser Object's content with <html> ... hence you do not need to be concerned about whether Javascript is enabled or not.

Similar to the technique suggested for ASCII text and Article objects, all you need to do is ...

- compose <html> text
- write it to a local file
- associate this file with the Browser object


And if you use (an old styled) mono-spaced font ... where fat characters like M and W occupy the same width as thin characters like I and 1 ... you can achieve a simulation of the old DOS BASIC commands ...

- start with 25 variables (e.g. [Line1], [Line2] ... [Line25]) with 80 "spaces"
- and 25 variables (e.g. [color1],[color2] ... [color25]) with 80 "0" characters (say color code for black)
- when you want column 7 of line 14 to be a red X, you can use the SubStr command to update the 7th character in [Line14] and [color14]
- have a subroutine that composes <html> from the 25 variables and writes to the local file
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Wrangler » Fri Mar 09, 2007 8:53 am

.. Set data in variable
setvar "[text]" "blah blah"

Set variable containing html code:

HTML code:

<html>
<head>
</head>
<body>
This is <font color="red">[text]</font> color one.
</body></html>

setvar "[html]" "<html> <head></head><body> This is <font color="red">[text]</font> color one. </body></html>"

This will produce:

This is blah blah color one.

Then:

filewrite [html] to file, say test.html

browsergoto the html file will display the above, with the variable text filled in for you neomagically.

You can create anything that can be shown in a web page. A trick is to create the layout you want in an html editor, even wysiwyg. Then copy the html source of the page to the [html] variable, and filewrite it to a html file.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby Wrangler » Fri Mar 09, 2007 8:53 am

.. Set data in variable
setvar "[text]" "blah blah"

Set variable containing html code:

HTML code:

<html>
<head>
</head>
<body>
This is <font color="red">[text]</font> color one.
</body></html>

setvar "[html]" "<html> <head></head><body> This is <font color="red">[text]</font> color one. </body></html>"

This will produce:

This is blah blah color one.

Then:

filewrite [html] to file, say test.html

browsergoto test.html will display the above, with the variable text filled in for you neomagically.

You can create anything that can be shown in a web page. A trick is to create the layout you want in an html editor, even wysiwyg. Then copy the html source of the page to the [html] variable, and filewrite it to a html file.

Using html tables, and a little experimentation, you can position the output so it displays in the browser according what you need.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest