Failure to call definition script

  • #1, by cr34m3Wednesday, 18. June 2014, 23:36 10 years ago
    Maybe someone can give me a hand here. I'm trying to call an execution script and keep getting this error in the log file:

    11:27:46 PM: [string "YPNo1: YPCheckSol: Execute script 'checksol..."]:2: attempt to call global 'checksol' (a nil value)
    11:27:46 PM: stack traceback:
    	[string "YPNo1: YPCheckSol: Execute script 'checksol..."]:5: in function 'checksol'
    	[string "YPNo1: YPCheckSol: Execute script 'checksol..."]:2: in function <[string "YPNo1: YPCheckSol: Execute script 'checksol..."]:1>
    	[C]: in function 'xpcall'
    	[string "YPNo1: YPCheckSol: Execute script 'checksol..."]:1: in main chunk
    


    It's like VS does not recognise that the function checksol exists.
    Here's the script (don't mind the prints and the expanded variable declaration -- I've been trying things to fix fhis for more than an hour now).

    P1PosV = getObject('Values[P1Pos]')
    P2PosV = getObject('Values[P2Pos]')
    P6PosV = getObject('Values[P6Pos]')
    P7PosV = getObject('Values[P7Pos]')
    P8PosV = getObject('Values[P8Pos]')
    P1PV = P1PosV:getInt(VValueInt)
    P2PV = P2PosV:getInt(VValueInt)
    P6PV = P6PosV:getInt(VValueInt)
    P7PV = P7PosV:getInt(VValueInt)
    P8PV = P8PosV:getInt(VValueInt)
    PuzCor = getObject('Conditions[PuzzleCorrect]')
    PuzIncor = getObject('Conditions[PuzzleIncorrect]')
    
    function checksol()
    	print("start checking")
    	wrongon = true
    	righton = true
    	poscomp = {P1PV, P2PV, P6PV, P7PV, P8PV}
    	possol = {3,2,4,5,1}
    	print("start righton check")
    	for k = 1 to 5 do
    		if poscomp[k] != possol[k] then
    			righton = false
    		end
    	end
    	print("start wrongon check")
    	for k = 1 to 5 do
    		if poscomp[k] == possol[k] then
    			wrongon = false
    		end
    	end
    
    	PuzCor:setValue(VConditionValue,righton)
    	PuzIncor:setValue(VConditionValue,wrongon)
    end
    


    Any help (or suggestions on where to look for the problem) will be greatly appreciated.

    Newbie

    72 Posts


  • #2, by afrlmeThursday, 19. June 2014, 01:03 10 years ago
    != ? it's lua...

    does not equal is: ~=

    I keep getting strange messages like that too when I run scripts that I've made a mistake in or forgot to close off properly. Only done that in the RC version so the error messages are probably some bug in the RC version as they should just give you a short error message & the offending line number.

    quick note: you should use " " instead of ' ' as they are safer. Especially when it comes to strings.
    str1 = 'Isn\'t it a wonderful day?'
    str2 = "Isn't it a wonderful day?"
    

    Nothing ground breaking...

    Also you might want to consider adding in a break inside of the for loops, just after the variable has been set as the rest of the i loops would be somewhat pointless.

    Imperator

    7278 Posts

  • #3, by cr34m3Thursday, 19. June 2014, 18:46 10 years ago
    Ok... I feel like an utter idiot right now.
    I fixed the ~= and got the same error. I read slowly through the code again and then spot the huge syntax error that I should have picked up long ago:
    for k = 1 to 5 do
    

    This is just sad... red

    Newbie

    72 Posts

  • #4, by afrlmeThursday, 19. June 2014, 19:28 10 years ago
    ai sus... I didn't spot that one either, but I did only give it a quick glance over.

    As for the 1, 5 part... I would probably have used table.maxn(possol) or #(possol), so it automatically adds the table total. I find it a bit more dynamic, in case the table might have data removed/added later on. Just a little tip/suggestion, but not important.

    Imperator

    7278 Posts