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 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2004
    Location
    Coventry, UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Function not defined error message

    Hi,

    Ive written a script and when ive run it on Netscape, it comes up with the function() not defined error message. Could someone please tell me what this is and how to fix it?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by lordofthesword8
    Hi,

    Ive written a script and when ive run it on Netscape, it comes up with the function() not defined error message. Could someone please tell me what this is and how to fix it?
    because your page can't find the function that you've written. might just be a typo, or it's being called at the wrong time.

    however, given that none of us are psychic (no really, we're not believe it or not), you'll have to supply some code for us to really decipher the problem. otherwise, we just can't help you.

  • #3
    New Coder
    Join Date
    Jun 2004
    Location
    Coventry, UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Thanks

    Thanks a lot for that definition it really helps

    Here is the code, and I would appreciate if you would have a go at cracking it for me.

    function attackcalc() {
    if (document.fight.answer.value=="A") {
    attackenemy()
    enemyattack(0)
    }
    if (document.fight.answer.value=="B") {
    enemyattack(parseInt(document.fight.herolevel.value))
    }
    if (document.fight.answer.value=="C") {
    document.fight.location.value = 'magicwrite'
    magiclist = new Array("Do you want to use:\rA. Fire Ball\r","Do you want to use:\rA. Fire Ball\rB. Meteor Ball\r","Do you want to use:\rA. Fire Ball\rB. Meteor Ball\rC. Shining Blade\r","Do you want to use:\rA. Fire Ball\rB. Meteor Ball\rC. Shining Blade\rD. Inferno\r","Do you want to use:\rA. Fire Ball\rB. Meteor Ball\rC. Shining Blade\rD. Inferno\rE. Final Blow")
    level = parseInt(document.fight.herolevel.value.value)
    document.fight.movelist.value = magicstring[level]
    }
    }

    function fireball() {
    if (parseInt(document.fight.yourcurrentmagic.value)>=5) {
    alert("You cast a Fireball!")
    var enemyhealth = parseInt(document.fight.enemycurrenthealth.value)
    enemyhealth = enemyhealth-5
    document.fight.enemycurrenthealth.value = enemyhealth
    }
    if (parseInt(document.fight.yourcurrentmagic.value)<5) {
    alert("You do not have enough Magic left to cast this!")
    }
    enemyattack(0)
    }

    function magiccalc() {

    if (document.fight.answer.value=="A") {
    fireball()
    }
    if (document.fight.answer.value=="B") {
    meteorball()
    }
    if (document.fight.answer.value=="C") {
    shineingblade()
    }
    if (document.fight.answer.value=="D") {
    inferno()
    }
    if (document.fight.answer.value=="E") {
    finalblow()
    }
    }

    function calccalc() {
    var location = document.fight.location.value
    if (location=="attackwrite") {
    atackcalc()
    }
    if (location=="magicwrite") {
    magiccalc()
    }
    }

    function youwrite() {
    var totalhealth = parseInt(opener.document.darkworlds.herolevel.value)
    document.fight.heroname.value = opener.document.darkworlds.hero.value
    document.fight.herolevel.value = opener.document.darkworlds.herolevel.value
    document.images.youpic.src=opener.document.darkworlds.hero.value + ".gif"
    document.fight.yourcurrenthealth.value = opener.document.darkworlds.health.value
    document.fight.yourtotalhealth.value = totalhealth*20
    totalmagic = parseInt(opener.document.darkworlds.herolevel.value)
    document.fight.yourcurrentmagic.value = totalmagic*10
    document.fight.yourtotalmagic.value = totalmagic*10
    }

    function enemywrite() {

    enemyname = getenemyname()
    enemylevel = getenemylevel()
    document.fight.enemycurrenthealth.value = enemylevel*20
    document.fight.enemytotalhealth.value = enemylevel*20
    document.fight.enemyname.value = enemyname
    document.fight.enemylevel.value = enemylevel
    document.images.enemypic.src=enemyname + ".gif"

    document.fight.enemycurrentmagic.value = enemylevel*10
    document.fight.enemytotalmagic.value = enemylevel*10

    }

    function getenemyname() {
    var loc = opener.document.darkworlds.location.value
    var enemy = ""

    switch(loc) {

    case "mountain1write":
    enemy = "Stone Snake"
    break

    case "mountain3write":
    enemy = "Mountain Troll"
    break

    case "mountain6write":
    enemy = "Elven Sentries"
    break

    }
    return enemy
    }

    function getenemylevel() {
    var loc = opener.document.darkworlds.location.value
    var enemy = 0

    switch(loc) {

    case "mountain1write":
    enemy = 1
    break

    case "mountain3write":
    enemy = 2
    break

    case "mountain6write":
    enemy = 3
    break

    }
    return enemy
    }

    function attackwrite() {
    document.fight.location.value = 'attackwrite'
    document.fight.movelist.value = 'Do you want to:\r A. Attack \r B. Defend \r C. Cast a Spell'
    }

    function attackenemy() {
    var yourattack = parseInt(document.fight.herolevel.value)
    yourattack = yourattack*2
    var enemyhealth = parseInt(docuemnt.fight.enemycurrenthealth.value)
    enemyhealth = enemyhealth-yourattack
    document.fight.enemycurrenthealth.value = enemyhealth
    }

    function start() {
    youwrite()
    enemywrite()
    attackwrite()
    }

    The function im having problem with is the attackcalc() function. I dont htink its being called and I put it first in case it was a missing {} but with no luck.

    Thanks for replying.

    LOTS8

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, wot function are you trying to call, and upon what event or action?

  • #5
    New Coder
    Join Date
    Jun 2004
    Location
    Coventry, UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation The function and the Event is...

    The function is calccalc() and the event is when the user clicks a button.

    What I want to happen with this script is that, when the button is pressed, the func calccalc() will see where you are in the script. In the first step it will then either attack, defend or write in a text box what spells you have to choose from. If you asked for the spell list the next time you click on the button it will run th eapropriate spell function depending on what your input was.

    Am I doing this in a roundabout way?

    Thanks

    LOTS8

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for a start, in your calccalc function, rename your location variable. it's an actual JS object and is a reserved word, so that's not gonna help. it may even be the source of the error.

    also, you can redefine the if statements in the magiccalc() using a switch statement. that would be better written and would parse quicker.

    also, use semi-colons at the end of each statement. it's good practice. like so:

    Code:
    function getenemyname()
    {
    	var loc = opener.document.darkworlds.location.value;
    	var enemy = "";
    
    	switch(loc)
    	{
    		case "mountain1write": enemy = "Stone Snake"; break;
    		case "mountain3write": enemy = "Mountain Troll"; break;
    		case "mountain6write": enemy = "Elven Sentries"; break;
    	}
    	
    	return enemy ;
    }
    Last edited by jbot; 07-05-2004 at 02:13 PM.

  • #7
    New Coder
    Join Date
    Jun 2004
    Location
    Coventry, UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Ooops!

    Thanks a lot for all this help.

    I did not realise location was a reserved word, and I will go through my script replacing it with loc. And thanks for the bit about using a switch statement, as it takes about five minutes trying to see the logic I used in the code. Also I did not realise you should put a ; after each line or statement. Can someone say why??

    LOTS8

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by lordofthesword8
    Also I did not realise you should put a ; after each line or statement. Can someone say why??
    LOTS8
    you don't have to put a semi-colon at the end of each line, but you do after each statement.

    however, i still think it's good practice to end a line with one, if only to err on the side of safety

  • #9
    New Coder
    Join Date
    Jun 2004
    Location
    Coventry, UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks Thanks Thanks

    Thanks for all this help, as my script is finally working!! Thanks you very much!!


  •  

    Posting Permissions

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