Digital Workshop

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Array question
PostPosted: August 17th, 2007, 10:24 am 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Hi all
If I have an array that has 6 words seprated by commas" like this
myWords = "SNAIL,BEE,CRICKET,ANT,FROG,JUNGLE";
myWords = myWords.split(",");
Now I want if the user put in the input text (myGuess) any of these words he'll have +1 score.


For this message opuslover has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: August 17th, 2007, 10:49 am 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Thanks for all
i've found the answer.


For this message opuslover has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: August 17th, 2007, 12:07 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
I have another question now.
I have a word of 6 letter in a variable.
I want it to be scramble into another variable.

example
the word "EXPAND" I want it to be scrambled into like "PDANXE" and if i press the button again it gives another scrambled word.


For this message opuslover has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: August 17th, 2007, 12:19 pm 
Offline
Godlike
Godlike
User avatar

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

Here's a solution for anybody else that needs to search an array for a specific term.

myWords = "SNAIL,BEE,CRICKET,ANT,FROG,JUNGLE".split(",")

myGuess = "SNAIL"



if (inArray(myGuess)) Debug.trace("Word found - increase score")




function inArray(str)
{
for (i=0;i<myWords.length;i++)
{
if (String.contains(myWords[i], str, true))
{
return true
} else
{
return false
}
}
}


AS for the anagram, you have to read each character using charAt and feed them in a random order into another array - finally concat all the elelemtns of the random array using the join command.

There are lots of randomising scripts on the forum or download the Opus Functions IMP from my website as it contains a randomising example that can be adapted.

Mack

www.interaktiv.co.uk

_________________
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 17th, 2007, 1:51 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Thanks Mac
I downloaded your function IMP it's really great.
But here just I want a hint to feed the letters into the array by using charAt.
Just give me the hint and i'll carry on


For this message opuslover has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: August 17th, 2007, 2:19 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
If memory serves me correctly, the inital array is called myNumbers and is simply loop feeding in zero to x. Change this loop to read the position of the string using the charAt.

Once you've read the letters into the myNumbers array, they will be randomised and feed into the myMix array. Use the join command to concat the randomised letters back to a string.

BTW this example has two lines that output to text boxes on the page, these can simply be removed.

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 17th, 2007, 10:12 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Thanks Mack
You always give great help here.


For this message opuslover has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Expand on same question of Array and matching
PostPosted: November 6th, 2007, 6:52 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
I figured it best to continue here rather than start new thread.

I tested Mac's code above, and great it works. Then I wanted to apply Array methods and I "broke it".

(see Mac's code below) I put the function in a Script Object. I used 2 buttons... one to populate the array elements, and another to test the match. Tried User Text Input for entering "jungle", "frog", etc to myGuess. Did set-up myWords and myGuess as page variables.

Here are my questions and issues.
1) I can only get the code to work if I change the "if statement" in the function to:

Code:
if (String.contains(myWords, str, true))  // remove the [i]  index

Why is that necessary? Is it right?

Also, I tried leaving the "[i]" in and creating another loop to sequence thru Array Elements. I couldn't get it working. How could this be done?

2) I wanted to prevent User 'null' input for myGuess. I tried to insert an If statement, if(myGuess==''), but mixed results. Not sure that belongs in the function or in the match-test??

Thanks.


Here's a repeat of the code with remarks how I divided it.

Code:
[/ Execute by Button1 script
myWords = "SNAIL,BEE,CRICKET,ANT,FROG,JUNGLE".split(",")

// Have User Text Input   to type in       jungle      instead of the line below
myGuess = "jungle"


// Use Button2 script
if (inArray(myGuess)) Debug.trace("Word found - increase score")


// Place this function code in a Script Object on the page  //seems this Obj must be high in the organizer
function inArray(str)
{
for (i=0;i<myWords.length;i++)
{
if (String.contains(myWords[i], str, true))    // does not seem to work within a Script Object
{
return true
} else
{
return false
}
}
}

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


For this message Lar_123 has been thanked by : mackavi


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 50 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