Understanding The basics of Lua Locals! menu

User Tag List

Results 1 to 2 of 2
  1. #1
    Dibes's Avatar Active Member
    Reputation
    18
    Join Date
    May 2008
    Posts
    47
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Understanding The basics of Lua Locals!

    LOCAL GUIDE!

    This is another little guide im making to describe a more advanced yet commonly needed command. The local command. The local command lets you use multiple NPCs in one script.

    Ok lets go!!

    to start a local value you use the command
    local npcname -- this means nothing it is just recognizing the name in the script you can change npcname into anything you want
    Now when you start your script you want to name the local value so it means something, for example
    function npclolz(pUnit, Event)
    npcname = pUnit -- this tells the script that this npc is named that! you can use as many npcs as you want using this!
    npcname:SendChatMessage(12, 0, "lol") -- npcname replaces pUnit and does its same function
    end
    you need to bind each function to an npc id, for example


    local npcname
    local npcname2

    function npcname(pUnit, Event)
    npcname = pUnit
    end

    RegisterUnitEvent(NPC ID, 1, "npcname")

    npcname2 = pUnit
    function npcname2(pUnit, Event)
    end

    RegisterUnitEvent(NPC ID, 1, "npcname2")
    Thats all i hoped you learned something! have fun!
    Last edited by Dibes; 07-11-2009 at 11:43 PM.

    Understanding The basics of Lua Locals!
  2. #2
    Vindicated's Avatar Contributor
    Reputation
    226
    Join Date
    Aug 2008
    Posts
    1,067
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you kinda failed to mention what local does, basically it makes it a local variable (as opposed to global) and the variable must stay in its "scope". For example, if you define the variable as a local variable OUTSIDE a method (Such as a function or conditional statement), then its scope is the entire file. It can be used in every function in the file if needed. If I defined it inside a function as a local variable, then it will be bound to it's scope, which is in this case that function only. It can't be used anywhere else. Hope that helps you clear stuff up You could add some examples of how scope works in your guide and some readable colors that are easy on the eyes and then your set


Similar Threads

  1. How to understand Lua - The Basics
    By Nymphx in forum WoW EMU Guides & Tutorials
    Replies: 4
    Last Post: 06-02-2009, 03:15 PM
  2. SQL 101: Understanding the Basics
    By SectorSeven in forum Programming
    Replies: 2
    Last Post: 05-21-2008, 12:36 PM
  3. the basics~
    By Sick Blood in forum WoW ME Questions and Requests
    Replies: 4
    Last Post: 01-05-2008, 10:41 PM
  4. Learning the Basics
    By Nkapocal in forum Community Chat
    Replies: 0
    Last Post: 12-13-2007, 09:14 PM
  5. Tanking For Dummies Part 1: The Basics
    By Krazzee in forum World of Warcraft Guides
    Replies: 1
    Last Post: 06-14-2006, 07:41 AM
All times are GMT -5. The time now is 03:53 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search