Spider Pork Posted July 5, 2010 Share Posted July 5, 2010 Hello there! Why is this function... function setPlayerRandomSkin(player) randskin = math.random(288) if(isValidSkin(randskin) == true) then if(isRegimentSkin(randskin) == false) then local account = getPlayerAccount(player) setAccountData(account, "wwacc.skin", randskin) setElementModel(player, getAccountData(account, "wwacc.skin")) return getAccountData(account, "wwacc.skin") else setPlayerRandomSkin(player) end else setPlayerRandomSkin(player) end end ... returning me the "Stack overflow." error? What does it mean anyways? Link to comment
50p Posted July 5, 2010 Share Posted July 5, 2010 "Stack overflow" means that this function has been calling itself without actually finishing execution of the first call. It's like infinite loop. Link to comment
MaddDogg Posted July 5, 2010 Share Posted July 5, 2010 A stack overflow happens, when data within the stack behind a memory location is overwritten, because the boundaries of your variable were not observed. This can happen, when pointers are not used correctly or an array index is exceeded. Or it could be an infinite loop. Your problem seems to be that you set your element model to a string. get- and setAccountData works with strings and does not support several types of data like get- and setElementData. Or your problem is the actual setting of the accountdata, although I don't know, how the function handles with unwanted data types. EDIT: I just saw that you recall the function over and over again, if an if clause is not fulfilled. That's your problem. Link to comment
Spider Pork Posted July 5, 2010 Author Share Posted July 5, 2010 I kinda knew it's because I call the function again. But how else can I find a good skin without calling the function again? If I just leave it, nothing will happen if it doesn't pass the checks. Link to comment
MaddDogg Posted July 5, 2010 Share Posted July 5, 2010 You could use a repeat-until loop. function setPlayerRandomSkin(player) repeat randskin = math.random(288) until isValidSkin(randskin) and not isRegimentSkin(randskin) local account = getPlayerAccount(player) setAccountData(account, "wwacc.skin", randskin) setElementModel(player, getAccountData(account, "wwacc.skin")) return getAccountData(account, "wwacc.skin") end Untested, but should work. But it seems like one of your functions has a problem, because it seems to always return the wrong value, so it will never pass and call the function again. Maybe post the code for isValidSkin and isRegimentSkin, there could be a problem in them, too. Link to comment
Spider Pork Posted July 5, 2010 Author Share Posted July 5, 2010 It works. Thanks a lot for your help. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now