HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] Need help with Colored Text, and IF statements please.  (Read 857 times)

AdvenCast

  • World Owners
  • ****
  • Posts: 14
    • View Profile

I am new to scripting, and I am trying to change the color of a message. This is the script i got:

function HelloWorld()
SendChat ("I like to eat Pine apple and bacon pizza!,", "game" )
.

I am trying to make the text black. I'm figuring its gonna be something with this script: $$COLORS #0,0,0,1.

I was guessing something like this:
function HelloWorld()
SendChat ("I like to eat Pine apple and bacon pizza!,", "game", $$COLORS #0,0,0,1)
.

I am most likely no where close. Please help me.

And about if statements. I know Action Script 2.0, and I was hoping the if statement usage was sort of like as2. But I can see its not. This is my guessing, how far off am I?

function HelloWorld()
if var textboxx == true
SendChat ("I like to eat Pine apple and bacon pizza!,", "game")
.
« Last Edit: Sep 26, 12, 09:43:20 AM by HE-Cooper »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Need help with Colored Text, and IF statements please.
« Reply #1 on: Sep 13, 12, 09:18:50 PM »

See GUI Label Markup for details of how to format text within a string.

Also, to reference a system node, use only one $, as in $COLORS.  If you don't want to set colors by their 4 numbers like shown on that wiki page, but instead by the name of a color, $COLORS has methods _GetForegroundMarkup and _GetBackgroundMarkup for getting the opening markup text which is mapped to a name. 
Those methods return the opening tag, but you still must add a closing tag to indicate where the coloring ends.  The closing tag is {/}

e.g. black text with red background:

Code: (hsl) [Select]
text = $COLORS._GetBackgroundMarkup("red")+$COLORS._GetForegroundMarkup("black")+"some text{/}{/}"
notice it needs two closing tags because of the two openers.


See the _ColorsClassMethods script for more details.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Need help with Colored Text, and IF statements please.
« Reply #2 on: Sep 15, 12, 02:25:57 AM »

Regarding if-statements, you do not use the var keyword in HSL if-clauses.  (var can be used for declaring a variable if you are assigning to it right away and then the value assigned determines the type of the variable.)

Also, for equality comparison, HSL does technically allow the use of single = in addition to double, but I always recommend continuing to use double.  That way, you don't fall into a bad habit of using single which can bite you later on if working in C again.  Also, it distinguishes the two usages allowing you to search for single when looking for assignment, and double when looking for equality comparisons.

Finally using ( ) is optional, and rarely used in the built-in code, but again you may wish to continue that practice since it is required in C.  And, of course, assuming that  textboxx is a boolean value, there is no need to compare it to true; since it is already bool, you can use it directly as the statement to be checked, as

Code: (hsl) [Select]
if textboxx
  SendChat ("I like to eat Pine apple and bacon pizza!,", "game")
.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Need help with Colored Text, and IF statements please.
« Reply #3 on: Sep 15, 12, 02:32:10 AM »

And I am just adding this so I can put in the 4500th post in Scripting!  :P
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.