Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Function return and strings

Function return and strings

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Dyron   (17 posts)  Bio
Date Wed 13 Feb 2013 09:12 PM (UTC)
Message
On Lusternia stances are able to avoid kicks. So I'm making an automated script to adjust my kick by their stance. I am having trouble with the return statement though. It's returning as a table and not a string.


tarstance = {}
tarstance.legs = false
tarstance.head = false



function yanker()
  local kicklimb = {}
  local kicklimb = dokick()
  send ( "kata perform " .. target .. " ninshihe" .. kicklimb )
end



function dokick()

  local toReturn = {}

    if not tarstance.head then 
	local toReturn = "he"
	Note ( "toReturn is " .. toReturn )
    else
	local toReturn = "rl"
	Note ( "toReturn is " .. toReturn )
    end
	
  return toReturn
end


The note shows it correct but when it returns it, it's a table it seems. How do I stop this?


Top

Posted by Bast   (78 posts)  Bio
Date Reply #1 on Wed 13 Feb 2013 09:45 PM (UTC)
Message
Dyron said:


function dokick()

  local toReturn = {}

    if not tarstance.head then 
	local toReturn = "he"
	Note ( "toReturn is " .. toReturn )
    else
	local toReturn = "rl"
	Note ( "toReturn is " .. toReturn )
    end
	
  return toReturn
end


The note shows it correct but when it returns it, it's a table it seems. How do I stop this?



Remove the local in the if else clause. The local keyword makes the scope of the variable only apply to the if or else part.

It should look like this

function dokick()

  local toReturn = {}

    if not tarstance.head then 
	toReturn = "he"
	Note ( "toReturn is " .. toReturn )
    else
	toReturn = "rl"
	Note ( "toReturn is " .. toReturn )
    end
	
  return toReturn
end


Bast

Bast

Scripts: http://github.com/endavis
Top

Posted by Dyron   (17 posts)  Bio
Date Reply #2 on Wed 13 Feb 2013 10:26 PM (UTC)
Message
Works like a charm! Thanks a ton.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


13,110 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.