Jump to content

Stack overflow


Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...