Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Can't Make 3 Similar Functions Work Together

    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:

    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!

    Code:
    <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>
    Last edited by tristevoix; 08-24-2008 at 01:47 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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

  • Users who have thanked Philip M for this post:

    tristevoix (08-24-2008)

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Cool, thanks for your tip, Philip! I'll try that right away.

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

    Cheers!

  • #4
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Took me a while, but I managed to make it work!
    I unexpectedly learned a new thing while doing so, too.

    Thanks again! ^_^


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •