Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 11:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: SetSelectionStyle not working on Text Object
PostPosted: September 21st, 2008, 4:33 pm 
Offline

Joined: March 21st, 2006, 10:37 pm
Posts: 31
Location: Grantham, Lincolnshire,UK
Hi, I am having a problem with the SetSelectionStyle() OpusScript command.

Basically, I have a text area with a variable in it called "TEXTGAME_CURRENT". The variable is a hangman display, so I want the correct guesses to be bold and underlined.

The following code only works when the character position that is passed to my ShowTextAsActive function is the first character.

Please help! The following is my code:

[code]
function BuildCurrentWordDisplay()
{

// Create the word to display
var wordLength = TEXTGAME_HIDDENWORD.length
TEXTGAME_CURRENT = ""
TEXTGAME_LETTER = "A"


var allLettersFound = true

for (var i = 0; i < wordLength; i++)
{


var sub = String.toupper(TEXTGAME_HIDDENWORD.charAt(i))
var bound = GetLetterBound(sub)
if (bound > 0)
{

// See if the letter exists in the guessed letters
var loop = 1
var found = false
while (TEXTGAME_GUESSED[loop] != null && found == false)
{

// Determine if the letter that's guessed matches the sub
if (sub == TEXTGAME_GUESSED[loop])
{
found = true
}

loop++

}


if (found)
{

TEXTGAME_CURRENT = TEXTGAME_CURRENT + sub + " "
ShowTextAsActive(i)
}
else
{
TEXTGAME_CURRENT = TEXTGAME_CURRENT + bound + " "
allLettersFound = false
}

}
else
{
TEXTGAME_CURRENT = TEXTGAME_CURRENT + sub + " "
}


}

// The word is now built up, show the next word
if (allLettersFound)
{
wait(1)
LoadNextWord()
}

}


// Shows the character at the specified position as active
function ShowTextAsActive(position)
{

var newStyle = new Object()
newStyle.bold = true
newStyle.underline = true

TextCurrent.SetSelection(position, position + 1)
TextCurrent.SetSelectionStyle(newStyle)

}[/code]

TextCurrent is the name of my Text object. The important part is the ShowTextAsActive function. It only works when the first character position is passed to it. If I pass any number greater than 0 it doesn't work. However, if I pass 0 to it, all of the text gets made bold and underlined.


Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: September 21st, 2008, 8:16 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Unless I misunderstand, the ShowTextAsActive function seems to select each letter individually as required.
The problem might be elsewhere.

Paul


Last edited by Paul on September 25th, 2008, 8:53 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: September 22nd, 2008, 8:12 pm 
Offline

Joined: March 21st, 2006, 10:37 pm
Posts: 31
Location: Grantham, Lincolnshire,UK
Thanks for trying to help.

Unfortunately it does not work when the text in the box is a variable, which is what my problem is.

Create a variable called "Test" as type "Text" and enter "ABCD". If you then put that variable in it does not work.

By the way, I am not using a text-entry box, I am using a Text-Label object.


Top
 Profile  
 
 Post subject:
PostPosted: September 22nd, 2008, 10:27 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
zesmail wrote:
Thanks for trying to help.

Please take a bit more time to explain fully, then I could have given a more suitable answer.

Paul


Last edited by Paul on September 24th, 2008, 3:00 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: September 23rd, 2008, 10:29 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
You would like the correct guesses to be bold and underlined, but working with variables can limit options on how text is displayed.
As a suggestion, I would show the correctly guessed letters and hide the rest of the word by substituting a question mark for the hidden letters.
That way you can work with a string and not be concerned about how it is formatted.

ie

"comfortable" could be shown partly solved as "co?for??ble"

Paul


Top
 Profile  
 
 Post subject:
PostPosted: September 25th, 2008, 8:56 pm 
Offline

Joined: March 21st, 2006, 10:37 pm
Posts: 31
Location: Grantham, Lincolnshire,UK
Hi again Paul, sorry for the delayed reply.

As you can see from this piece of code, I am doing that already:


if (found)
{

TEXTGAME_CURRENT = TEXTGAME_CURRENT + sub + " "
ShowTextAsActive(i)
}
else
{
TEXTGAME_CURRENT = TEXTGAME_CURRENT + bound + " "
allLettersFound = false
}

}
else
{
TEXTGAME_CURRENT = TEXTGAME_CURRENT + sub + " "
}


However, I am not using Question marks, I am using a number based on a mobile phone.

I.e. HELLO WORLD would be something like H355O WO753.

However, doing it this way means that the letters and numbers together are very confusing. I cannot use question marks as the whole point of the Hang-man style game is on the relation to the letters to the mobile numbers.

So, I take it I can categorically NOT do what I want with bolding/underlining when using a variable?


Top
 Profile  
 
 Post subject:
PostPosted: September 25th, 2008, 10:06 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
OK, now I understand.
You can't do it using one variable in one text object.

One suggestion -- if you broke it down into a series of one letter textboxes each containing a one letter variable, you could apply formatting to the text boxes individually as required -- that would be fairly complex but would probably give the result you are after.

Paul


Top
 Profile  
 
 Post subject:
PostPosted: September 26th, 2008, 7:54 am 
Offline

Joined: March 21st, 2006, 10:37 pm
Posts: 31
Location: Grantham, Lincolnshire,UK
Thanks, is there any way to programatically create a text input box then? Each time the game is played, a different word is shown, so I never know how long the word will be.


Top
 Profile  
 
 Post subject:
PostPosted: September 26th, 2008, 8:17 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
You never know how long the word will be but there are limits -- 25 characters will cover all words I can think of.
You can clone text boxes with script in Opus (look up CloneObject() in the docs), but the easiest (and best) way is to make enough hidden boxes (with their variables built in) then show the required number when needed.

Paul


Top
 Profile  
 
 Post subject:
PostPosted: September 28th, 2008, 4:25 pm 
Offline

Joined: March 21st, 2006, 10:37 pm
Posts: 31
Location: Grantham, Lincolnshire,UK
Unfortunately, it can potentially be a phrase of about 10 words.


Top
 Profile  
 
 Post subject:
PostPosted: September 28th, 2008, 7:17 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Still possible.
However -- since you keep drip feeding information, I feel that my time is being wasted.
Good luck with your project.


Top
 Profile  
 
 Post subject:
PostPosted: September 29th, 2008, 4:18 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
One approach it to have User Text Input boxes AND a separate area for displaying text(s) entered. This is very easy and updates almost immediately. Then do the manipulation of style on the regular Text Object.

Lots of ways to concatenate... and to keep track of matching or correct entries.

I agree with Paul BTW... there is no complete picture here of the challenge. Not very inviting to try to guess what's needed or wanted.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: September 29th, 2008, 8:44 pm 
Offline

Joined: March 21st, 2006, 10:37 pm
Posts: 31
Location: Grantham, Lincolnshire,UK
Ok, I'll take your comments on board and re summarise this.

Firstly, as per my original post, I am using a variable in a Text object to display the result of a hang man letter guessing game. That variable is updated using opusscript to display the correct guesses and what is still yet to guess.

What I forgot to mention is that those letters that are yet to be guessed are masked by a number. That number relates to the letters position on a mobilephone keypad. I.e. ABC all will be shown as 1, CDE are all show as 2 (when unguessed). This is done in my code (in my first post) when the match is missed it is replaced by the local variable called "bound". "bound" is the number that the letter is bound to. I should have explained the meaning of that variable, but you know what it's like when your code is obvious to yourself, you forget to explain it thoroughly.

Thanks for your comments Lar_123, but I don't understand what you mean? Do you mean I can pass my variable into a Text Input box and then have that send the text into the Text object for displaying? Will that text no longer be treated as a variable and will be treated as text?

I've thought from the offset that variables can not have this done to them as the changes only worked when SetStyle was applied to the start of the variable. Is there any way to insert the plain text into the object as I think that would solve the issue? But from what I read you cannot change the text at run-time unless using a variable.

Thanks in advanced, and your help would still be appreciated Paul if you get time.


Top
 Profile  
 
 Post subject:
PostPosted: September 30th, 2008, 3:33 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Zes,

I won't take time to get into details of your project, but I will try to provide some help from what I learned.

User Text Input objects can of course place the input into a variable. With some OpusScript code, that same "box" can display text updated by a variable.
AND ALSO... it is very convenient to have a separate normal Text Object to display text and words as they are being updated. If you had for example 3 Text Input objects... going to variable01, variable02, variable03 --- then that normal Text Box could display a 'mix' of static text and the variables.

For example:
Quote:
Your guess for the city is <variable01>, and your estimate of drive time was <variable02>. You said the purpose for the trip was <variable03>.
As you probably know already, you use Right-click on the Text Object and select "Insert Variable" to place these within other static text (or alone without static text).


Do a Search on the Forum. (e.g., text input)
Here is something that may help... has attached a great Sample .imp file from Mackavi and then there are some refinements to the scripting I found very useful, thanks to Opuslover.
viewtopic.php?t=2688&highlight=text+input

As for the special formatting and bolding, you might look up 'length' as a function and also as that applies to properties... perhaps using Arrays. Do a Search on array or arrays, plus whatever other keywords come to mind.

Good luck.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group