+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: A question about functions.

  1. #1
    Wire Noob libintia's Avatar
    Join Date
    Jul 2010
    Location
    Sweden (But not a swed )
    Posts
    13

    Question A question about functions.

    2 days ago i watched a random Lua Video Lua tutorial. The guy making the tutorial creates this function :
    Code:
    function FishCake( ply )
        ply:concommand(" say F@#!ING MIGNBAGS ")
    end
    This right here
    Code:
    (ply)
    ...is driving me insane.

    Why did he put the ( ply ) after creating the function?
    is it important? Do i need to do that if i wanted to use the player in my function?

    I asked the author of the video, but i did not understand what he meant.



    ]skip to 0:40
    Last edited by libintia; 07-27-2010 at 07:38 AM.

  2. #2
    Wire Sofaking Wodden's Avatar
    Join Date
    Sep 2007
    Location
    location.sh &> /dev/null
    Posts
    446

    Default Re: A question about functions.

    ply is an argument of the funtion FishCake. An for concommand.Add, ply equals the player who ran the concommand.
    “Saying Java is good because it works on all operating systems is like saying anal sex is good because it works on all genders.”

  3. #3
    Wire Noob libintia's Avatar
    Join Date
    Jul 2010
    Location
    Sweden (But not a swed )
    Posts
    13

    Default Re: A question about functions.

    Quote Originally Posted by Wodden View Post
    ply is an argument of the funtion FishCake. An for concommand.Add, ply equals the player who ran the concommand.
    ok, i know ply stands for player. but,
    Do you mean that ply argument in the FishCake is (just a variable that's) unrelated to the one in concommand?

  4. #4
    Wire Sofaking Grocel's Avatar
    Join Date
    Mar 2008
    Location
    Germany, NRW, Remscheid
    Posts
    751

    Default Re: A question about functions.

    Quote Originally Posted by libintia View Post
    ok, i know ply stands for player. but,
    Do you mean that ply argument in the FishCake is (just a variable that's) unrelated to the one in concommand?
    When you call FishCake then you have to enter FishCake(ply) in your code, don't forget to set the variable of ply before call FishCake with ply = player.GetAll()([1] for example.
    Quote Originally Posted by Wizard of Ass View Post
    The secret phrase in gmod is: Rusty bullet hole
    Im a molecule!

  5. #5
    Wire Noob libintia's Avatar
    Join Date
    Jul 2010
    Location
    Sweden (But not a swed )
    Posts
    13

    Default Re: A question about functions.

    Quote Originally Posted by Wodden View Post
    ply is an argument of the funtion FishCake. An for concommand.Add, ply equals the player who ran the concommand.
    Thanks for your time.

    Quote Originally Posted by Grocel View Post
    When you call FishCake then you have to enter FishCake(ply) in your code, don't forget to set the variable of ply before call FishCake with ply = player.GetAll()([1] for example.
    it makes sense. thanks a lot.

  6. #6
    Wire Sofaking Wodden's Avatar
    Join Date
    Sep 2007
    Location
    location.sh &> /dev/null
    Posts
    446

    Default Re: A question about functions.

    Quote Originally Posted by libintia View Post
    it makes sense. thanks a lot.
    No it doesn't, the variable ply is set when someone runs the command "gm_talk_text".
    “Saying Java is good because it works on all operating systems is like saying anal sex is good because it works on all genders.”

  7. #7
    Wire Noob libintia's Avatar
    Join Date
    Jul 2010
    Location
    Sweden (But not a swed )
    Posts
    13

    Default Re: A question about functions.

    Quote Originally Posted by Wodden View Post
    No it doesn't, the variable ply is set when someone runs the command "gm_talk_text".
    Well, i don't think i get why he used the ply argument when he created the function, as far as i know, ply = player or LocalPlayer by default. Witch means that he didn't have to use it as an argument.
    he could have just use it directly

    like this for example:
    function FishCake()
    ply:comncommand(" say F@#!ING MIGNBAGS ")
    end
    But in any case I'm new to LUA and I am trying to understand how this works. I am currently reading (Lua Programming in Lua (first edition) ), and I'm almost done reading the functions section, but according to Chapter 5( Functions ): We pass parameters to the function so that we can pass arguments from outside the function or when we call the function.
    or am i wrong?

    This is very confusing! LUA is confusing.
    But i do appreciate your help, thank you.

  8. #8
    Wire Sofaking Wodden's Avatar
    Join Date
    Sep 2007
    Location
    location.sh &> /dev/null
    Posts
    446

    Default Re: A question about functions.

    Quote Originally Posted by libintia View Post
    Well, i don't think i get why he used the ply argument when he created the function, as far as i know, ply = player or LocalPlayer by default. Witch means that he didn't have to use it as an argument.
    he could have just use it directly.
    It doesn't work that way either. Imagine, you create a function:
    Code:
    GiveAR2Ammo
    And you want to pass a player object and how much ammo you want to give. You would do:
    Code:
    function GiveAR2Ammo(Player,Amount)
        Player:GiveAmmo(Amount,"ar2",true)
    end
    Now you have your function, now you call it by running:
    Code:
    GiveAR2Ammo(player.GetByID(1), 250)
    Now you are passing a Player entity and a number as arguments to the function. Inside of the function you can access them like any variable.
    “Saying Java is good because it works on all operating systems is like saying anal sex is good because it works on all genders.”

  9. #9
    Wire Noob libintia's Avatar
    Join Date
    Jul 2010
    Location
    Sweden (But not a swed )
    Posts
    13

    Default Re: A question about functions.

    Quote Originally Posted by Wodden View Post

    It doesn't work that way either. Imagine, you create a function:

    And you want to pass a player object and how much ammo you want to give. You would do:

    Now you have your function, now you call it by running:

    Now you are passing a Player entity and a number as arguments to the function. Inside of the function you can access them like any variable.

    .
    I think i finally, get it.
    He Used the ( ply ) as a parameter, only so that he can decide witch player the function will take effect on when he calls the function later on!
    i.e.
    ply is just a parameter nothing more!

  10. #10
    Wire Sofaking Wodden's Avatar
    Join Date
    Sep 2007
    Location
    location.sh &> /dev/null
    Posts
    446

    Default Re: A question about functions.

    “Saying Java is good because it works on all operating systems is like saying anal sex is good because it works on all genders.”

+ Reply to Thread
Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots