Function() has a nil value

by Simimi

Back to Mechanic's Corner.

Simimi2008-06-23 10:37:12
I have 5 functions. 3 of them work and 2 do not. 1 of the working ones and one of the non working ones are almost exactly the same herbcuring() and salvecuring(). Herbcuring works but Salvecuring doesn't... and now nether does autosipper()? They have stuff in them? What is going on here...

CODE
:11: attempt to call global 'autosipper' (a nil value)
stack traceback:
    :11: in main chunk
That trigger is calling autosipper() which looks as follows in the script:
CODE
--*AUTOSIPPER

function autosipper()

  if bals == "curing" or

     bals == nil then

      return nil

  end



if var.autosipper == "true" then

I do not know why it is a nil balance, all of my other similar functions work, but not these two. The error is the same for both. Just for smiles here is herbcuring() and salvecuring()
CODE
function herbcuring()

  if bals == "curing" or

     bals == nil then

    return

  end

function salvecuring()

  if bals == "curing" or

     bals == nil then

    return

  end


I am stumped and it is driving me nuts! All I do was reimport my autosipper from a plugin to be in the actual system, for easier editing as it needs a lot of work to be pvp ready, and the function call does not want to work... any ideas?
Nezha2008-06-23 11:44:31
is this all the info? cant really diagnose the problem with just this.. maybe zarquan can though.. hehe..
Simimi2008-06-23 11:55:52
Ok I can give the entirity of the functions if you want... what more info would be helpful?
Nezha2008-06-23 12:05:34
well see, i only encounter errors like this if

1. The function the trigger was calling was deleted. or replaced and its still calling the old function..
2. Therefore: I usually delete all the old function/trigger/timers when im loading a new batch of function/trigger/timers to make sure its fresh.

Other than this, i cant recall facing such kind of errors before..
Simimi2008-06-23 12:10:55
Well I added it to the script and then reloaded the script and removed the same plugin, then reloaded the script again and still the one prompt trigger can not call either function without the error, when similar functions like herbcuring() and prompttracker() work just fine...

It -seems- now that salvecuring works and autosipper doesn't...

EDIT: and for some reason now they both seem to work as intended and I did nothing!
Nezha2008-06-23 12:18:11
1. are you sure there are no conflicting triggers of the same name? or conflicting functions of the same name?
2. when you say reload, is it a deletefirst-reload or jsut a reload?

:puzzled:
Simimi2008-06-23 15:27:10
Just a reload. I turned off mush, reloaded the script, and started again...
Daganev2008-06-23 16:10:02
Are you sure you want to use "return" and not "break" or something of that nature?

I don't know much about mush, but in most languages when you use "return" you have to return an object, and you have to set a type of your function of which you are returning.

In this case your fucntions are of type void, and are returning nil or null instead of void. A void function normally means that it doesn't have a return statement.

But this could be a different thing in this language.
Daganev2008-06-23 16:11:57
Also, you might just have to add "return nil" instead of of just "return" to your functions to make them work consistently.

I imagine the reason why sometimes it works and sometimes it doesn't is that sometimes you have values set before the function calls and sometimes you don't. But I could be compelely wrong about this. wouldn't be surprised if I was.
vorld2008-06-23 16:34:00
What programming language is this?
Simimi2008-06-23 23:20:40
Dags: You are right, I gave them value before the reload and did not notice it: I will change to return nil and see what happens.

Vorld: Lua
Unknown2008-06-24 01:59:34
Just a "return" is fine if all you want to do is leave the function. If these functions are being evaluated as part of some other expression (i.e., if autosipper() then blah end), you need to return some sort of value for it to compile and execute correctly. I agree with Nezha, though, that a little more context would help to solve the issue.
Simimi2008-07-06 04:58:26
Well it wasn't fixed, as soon as I fired up Mush again I got the same error, and now trying to fix it is proving pointless. I think I might scrap the whole system and start over. I have so much extra script for other things besides healing that it is becoming a pain to find out what is causing this to work one day and then not the next... Anyway...

I'm still getting that the function has a nil value, even though the var.autosipper is true. I get this on script load, and I even set the value before loading the script...
Malarious2008-07-06 06:26:59
QUOTE(Simimi @ Jul 6 2008, 12:58 AM) 529330
Well it wasn't fixed, as soon as I fired up Mush again I got the same error, and now trying to fix it is proving pointless. I think I might scrap the whole system and start over. I have so much extra script for other things besides healing that it is becoming a pain to find out what is causing this to work one day and then not the next... Anyway...

I'm still getting that the function has a nil value, even though the var.autosipper is true. I get this on script load, and I even set the value before loading the script...


Geeve us da snippet of whats broken? or at least an example?
Daganev2008-07-06 16:35:51
Perhaps the function is fine, but the way you are tryin to call the function is wrong?
Unknown2008-07-06 18:51:14
The fault seems to lie in the prompt trigger, by the looks of it. I see no inherent bug in the functions you've posted, so how about that trigger?
Simimi2008-07-07 06:15:25

enabled="y"
group="tracking"
match="^(\\d+)h, (\\d+)m, (\\d+)e, (\\d+)p, (\\d+)en, (\\d+)w (e?s?S?i?l?r?x?k?b?d?p?)(\\<\\>)?\\-$"
name="prompt"
regexp="y"
send_to="12"
sequence="100"
>
var.health = "%1"
var.mana = "%2"
var.ego = "%3"
var.power = "%4"
var.endurance = "%5"
var.willpower = "%6"
var.promptstring = "%7"

autosipper()
promptcheck()
herbcuring()
salvecuring()