PDA

View Full Version : Need help with my Lua code - error



NeonGenesis
June 2nd, 2006, 06:03
Issue resolved. Link no longer active.

Moderators, please delete. Thanks.

b8a
June 2nd, 2006, 08:55
I'm not a lua scripter, but right off the bat I noticed some spelling problems.
-- --------------------------------------------
-- Color Gradient function for player locatiion
-- --------------------------------------------
--function PL_Gradient(p_color)
-- if color_up == true and p1_red > 15 then
-- p1_red = p1_red - 20
-- p1_blue = p1_blue + 20
-- p1_green = p1_green + 20
-- end
--
-- if color_up == true and p1_red == 15 thenn
-- color_up = false
-- end
--
-- if color_up == false and p1_red < 255 theen
-- p1_red = p1_red + 20
-- p1_blue = p1_blue - 20
-- p1_green = p1_green - 20
-- end
--
-- if color_up == false and p1_red == 255 thhen
-- color_up = true
-- end
--
--p_color = Color.new(p1_red, p1_green, p1_bblue)
--return p_color
--end

How many times can you find a misspelling of "then" in this code? Also looks like you have an extra b in "p1_bblue" as well. If the posted code is the code you've been having problems with, I'd first go over all of the spelling in the entire script with a fine-tooth comb and correct it all. If you're still having problems, come back here and post the code. Chances are the spelling's tripping you up, but if it isn't the spelling, at least you'll have taken care of one obvious culprit.

Edit:
My appologies. I only skimmed the text in the linked page before I looked at the script, so I entirely missed that you were looking for info on a specific function. I stopped taking a close look at the script when I caught several misspellings. Although, now that yaustar mentions it, I think they were pretty much all in sections that were commented out.

Sorry, I should have paid closer attention to what you took the time to describe.

yaustar
June 2nd, 2006, 09:04
As far as I can tell, there is nothing wrong with the function, but more to the fact the variables that you are passing are not the 'right' type. Lua is typeless meaning that a variable could be a number, text, image etc. You just have to be 100% that the variables that you passing are the right type.

This is why Lua should NOT be used as a programming language and why it IS a scripting language.

b8a: Doesn't matter, that section is commented out.

NeonGenesis
June 3rd, 2006, 01:36
Thanks to anyone who checked the code, but a good night's sleep revealed the problem to me.

It is not an issue with the function at all. There is no issue with the type of data I try to test in the function, or anything of the sort. Rather, it was the simple replacement of two plus signs with two minus signs elsewhere in the code. I hadn't yet bothered to implement an aditional test for the borders, and my adding to a variable instead of subtracting was causing the function to try to test for a pixel that was not within the image limits.

And, yes, I know the gradient function isn't proofread. ;) I didn't waste my time really messing with it, as it was leftover from another one of my projects, and I just left the code basis there in case I wanted to do something with it in this project.

Any moderator wishing to delete this thread, feel free. Thanks.