Digital Workshop

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Random Array Question
PostPosted: August 18th, 2007, 3:18 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Hi all
I want to declare some arrays in the script like this
Words1="I am a spammer,xxxx,I am a spammer,xxxx,xx"
words2="xxxx,xxxx,I am a spammer,ddd,mmm,I am a spammer"
and so on
NOw my question
Should I declare each array individually?
and if I want to read the array can I use something like word+String.random(4)
When I use it in opus it gives me undefined variable.
What is the right way to read them without declaring each array individually?


Top
 Profile  
 
 Post subject: Random Array Question
PostPosted: August 20th, 2007, 12:21 am 
Offline

Joined: March 8th, 2005, 9:40 pm
Posts: 63
Hi opuslover,

I am a virgin at answering posts, so I am very reluctant to do so, but there are several inconsistencies in your post.

Words1 has the first letter capitalised.
words2 does not.

Then you state "and if I want to read the array can I use something like word+String.random(4)"
In this, are you are using word+string instead of words+string or Words+string.

I have learnt (very quickly) on this forum, that if your post is not accurate, or if it is not specific, you are unlikely to get a reply.

In my very limited experience, all of the above errors could affect your code, unless they are just forum typo's.

I hope this helps you to get a more helpful reply.

Regards

Neil

_________________
Opus Pro V6
Dell Inspiron 9400
Intel Centrino Duo 2GHz
2 Gig Ram
XP SP2


Top
 Profile  
 
 Post subject:
PostPosted: August 20th, 2007, 9:54 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi opusLover,

Not quite sure what it is you want. If you need each of the words in an array element use:

words1 = "fish,cat,rat,mouse,house,boat,float".split(",")

This will make myWords[0] equal fish etc

IF YOU NEED the second array (words2) seprately, then yes you will also need to define this - else fill the first array with these words as an when you need them.

To get a random word from an array use:

myRandomWord = words1[String.random(words1.length)]

NOTE: This use of 'length' is not the same as the one in the manual to find the lenght of a string!!

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: August 20th, 2007, 3:22 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Thanks alot Mack.
you're always helping.

But I have one more question here.

words1 = "fish,cat,rat,mouse,house,boat,float".split(",")
how can I clone these words into boxes
let me explain more
I'll create a textbox with the name CT it's 20X20 in size I want this box to be cloned in the page as my array length.
In this case the first box will be 4 letters because words1[0] is 4 and I want the second box under the first one to have 3 for words[1] etc...

2. I want also the script to fill the box with letters from the array.


Top
 Profile  
 
 Post subject:
PostPosted: August 20th, 2007, 6:11 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Not quite sure what you mean.

Are you simply trying to clone text boxes to about the size of the string so that a four letter word will appear in a short box but a twelve letter work will appear in a longer box?

This would be possilbe, not hugely accurate, and would depend on the size & type face of your font.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: August 20th, 2007, 8:33 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Thanks Mack for your respond
Not exactly what I want.
I want to read the first item of the array then use length to see how many letters After that I want to clone four blank boxes on the page Finally when I press abutton I want the four letters to be shown in each textbox according to the order I put them in

By the way I can do it by only one item like this

First I create a text box and call it TC .
then I'll out this script for abutton
Code:
words1 = "fish,cat,rat,mouse,house,boat,float".split(",")
for (var I=1; I <= words1[0].length-1;I++)
{
var ty=TC.GetYPosition()
var tx=TC.GetXPosition()
TC.CloneObject(tx,ty+20*I,true)
}



THIS will clone four text boxes under each other
because the first item in the array is 4 letters.
What I dont know
1.how to do the same thing for all the array.
2. how to put the letters into the boxes.

I hope this clearify my question.


Top
 Profile  
 
 Post subject:
PostPosted: August 21st, 2007, 10:28 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Morning Opuslover,

I think what you need is to nest two for statements:

The first is a loop that reads through each each cell until array lenght is reached.

The second, inside the first, reads the actual lenght of the string inside the cell and and then uses charAt to determine the individual characters of the string. I might be wrong, but I think you need to use String.length(myArray[x]) to find the lenght of a string in cell X.

In theory, it looks something like this :-))))))

//Read each array cell
for (i=0; i<myArray.length;i++)
{

//Read lenght of string in each cell
for (a=0; a<String.lenght(myArray[i];a++)
{

//read the letters in the string of cell x
//You'll need something more advanced to deal with >1 letter
LETTER = myArray[i].charAt(a)

}

}

Mack,

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: August 21st, 2007, 4:05 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Excellent Job mack
Only the letters.
does the first clone text box need a constant variable to display the letters as you gave me before for the Dbase
That one was
TCarray[this.GetName().substring(3,this.GetName().length)-2147483647]


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 42 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