...

View Full Version : Resolved Can't Make 3 Similar Functions Work Together



tristevoix
08-23-2008, 11:52 AM
Hi,

How's you? =)

I'm new to java stuff. All I've been doing so far is using a generator code from www.seventhsanctum.com. I have not had any problem in the past until now.

What I'm trying is to have more than one generator on the same page. However, only one of them works at any given time and that is always the one which is listed last in this part of the code:



aVocab[intCat]= new Array();
aVocab[intCat][0]="INN"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<INNA> <INNB>"

aVocab[intCat]= new Array();
aVocab[intCat][0]="RACE"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<RACEA> <RACEB> <RACEC>"

aVocab[intCat]= new Array();
aVocab[intCat][0]="RAIN"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<RAINA> <RAINB> <RAINC>"


Here, I can only generate rain stuff. If I put the INN array under RAIN, I can only generate INN stuff.

I've searched around for solutions. One was about using ONLOAD: blah(); yada(), but couldn't make it work (might have done it wrong). The other solution was about using objects, but by the looks of it I think I couldn't achieve that on me own in a reasonable amount of time. Which is why I'm seeking help here, though I'm still trying!

So, I'd appreciate any assistance, even if it's only a nudge in the right direction. ^_^

Thanks very many much!



<HTML>
<HEAD>
<script language="JAVASCRIPT">

<!--
var aVocab = new Array();

var intIncr
var intCat

intCat =0
intIncr=0


aVocab[intCat]= new Array();
aVocab[intCat][0]="INN"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<INNA> <INNB>"

aVocab[intCat]= new Array();
aVocab[intCat][0]="RACE"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<RACEA> <RACEB> <RACEC>"

aVocab[intCat]= new Array();
aVocab[intCat][0]="RAIN"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<RAINA> <RAINB> <RAINC>"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="INNA"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Grand"
aVocab[intCat][1][intIncr++]="Great"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="INNB"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Hotel"
aVocab[intCat][1][intIncr++]="Manor"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="RACEA"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Dark"
aVocab[intCat][1][intIncr++]="Wild"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="RACEB"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Elf"
aVocab[intCat][1][intIncr++]="Orc"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="RACEC"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Savage"
aVocab[intCat][1][intIncr++]="Treehugger"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="RAINA"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Feisty"
aVocab[intCat][1][intIncr++]="Foxy"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="RAINB"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Cold"
aVocab[intCat][1][intIncr++]="Warm"

intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="RAINC"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="Mist"
aVocab[intCat][1][intIncr++]="Shower"

function GenNumber(nRange)
{
var iNumGen
iNumGen = Math.round((Math.random() * nRange));
return iNumGen;
}

function GetFrom(aArray)
{
var undefined
var sReturn
sReturn = aArray[GenNumber(aArray.length)];
if (sReturn == undefined)
{
sReturn = GetFrom(aArray)
}
return sReturn
}

function GetArray(sArrayName)
{
for (var intLooper=0;intLooper <aVocab.length;intLooper++)
{
if (aVocab[intLooper][0]==sArrayName)
{
return aVocab[intLooper][1];
break;
}
}
}

function ScanLine(sLine)
{
var iTagStart, iTagEnd
var sKey
if (sLine.indexOf("<") > -1)
{
iTagStart = sLine.indexOf("<");
iTagEnd = sLine.indexOf(">");
sKey = sLine.substr(iTagStart+1, iTagEnd-(iTagStart+1));
sKey = GetFrom(GetArray(sKey))
sLine = sLine.substr(0, iTagStart) + sKey + sLine.substr(iTagEnd+1, (sLine.length - iTagEnd))
}
if (sLine.indexOf("<") > - 1)
{
sLine = ScanLine(sLine)
}
return sLine;
}

function GenRace()
{
sLine = GetFrom(GetArray("RACE"));
sLine = ScanLine(sLine)
document.GENRACE.RACE.value = sLine;
}

function GenRain()
{
sLine = GetFrom(GetArray("RAIN"));
sLine = ScanLine(sLine)
document.GENRAIN.RAIN.value = sLine;
}

function GenInn()
{
sLine = GetFrom(GetArray("INN"));
sLine = ScanLine(sLine)
document.GENINN.INN.value = sLine;
}
//-->

</script>
</head>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000000" VLINK="#000000" ALINK="#FF80FF">
<center><FONT COLOR="#FF80FF"><B>Inn Names</B></FONT></center>

<center><form name="GENINN">
<table border="0">
<tr><td><textarea name="INN" rows="1" cols="30" READONLY></textarea></td></tr>
<tr><td align="center"><input type="button" name="BGENINN" value="Generate" onclick="GenInn();"></td></tr>
</table>
</form></center>
<br>
<br>
<br>
<center><FONT COLOR="#FF80FF"><B>Races</B></FONT></center>
<center><form name="GENRACE">
<table border="0">
<tr><td><textarea name="RACE" rows="1" cols="30" READONLY></textarea></td></tr>
<tr><td align="center"><input type="button" name="BGENRACE" value="Generate" onclick="GenRace();"></td></tr>
</table>
</form></center>
<br>
<br>
<br>
<center><FONT COLOR="#FF80FF"><B>Rain Types</B></FONT></center>
<center><form name="GENRAIN">
<table border="0">
<tr><td><textarea name="RAIN" rows="1" cols="25" READONLY></textarea></td></tr>
<tr><td align="center"><input type="button" name="BGENRAIN" value="Generate" onclick="GenRain();"></td></tr>
</table>
</form></center>
</body>
</html>

Philip M
08-23-2008, 12:49 PM
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.

You cannot have multiple scripts with the same function and/or variable names as (as you have discovered) the second over-writes the first.

So you will need to distinguish the three scripts by a prefix or suffix to all the function and variable names.

e.g: aVocab1, aVocab2 and aVocab3.


Quizmaster: In mythology, what term for a potion that increases sexual desire is derived from the name of the Greek godess of love?
Contestant: Viagra

tristevoix
08-23-2008, 02:18 PM
Cool, thanks for your tip, Philip! I'll try that right away.

And thanks for the clarification about java and javascript. ^_^

Cheers!

tristevoix
08-24-2008, 01:41 AM
Took me a while, but I managed to make it work!
I unexpectedly learned a new thing while doing so, too.

Thanks again! ^_^



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum