Thread Tools Display Modes
06-26-14, 01:24 PM   #1
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
How do i run my code?

Hey there,
i just started learning how to programm with LUA. Therefore i bought this book. http://www.lua.org/pil/
The problem i am confronted with now: I dont know how to execute my code that i just made during the "lesson" from the book.
I found this: http://www.lua.org/cgi-bin/demo
But actually i want to be able to execute my code offline.
I am using Notepad++ to code.

Can someone help me with this? I so badly want to see the "Hello World"-line
  Reply With Quote
06-26-14, 01:30 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
If you're not using any of the WoW API, an external Lua interpreter will work for you. But you are, so you need to be in game.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-26-14, 01:56 PM   #3
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
Makes sense i guess...kinda embarrassed right now. stupid brain fucked up x)
  Reply With Quote
06-26-14, 08:56 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You're not the first person to have asked.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-28-14, 04:48 AM   #5
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
Any ideas how to start writing simple addons to learn the basics of addon creation? Right now the only thing i can do is Simple math function, compare values and print messages in chat
  Reply With Quote
06-28-14, 05:17 AM   #6
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Here's a "little" text that I wrote for someone for getting-started purposes:

First of all, getting to know at least the basics of the language is obviously useful before delving into the WoW API. There is a guide available here. I didn't learn by it myself, so I can't say how good it is.
For hard facts there is the reference manual. (note that not everything is available in WoW, namely file handling functionality)
You'll want to learn how to use variables, tables and functions and function arguments for starters. Also if-cases and loops.
There's a demo page here where you can try stuff out. (hint: use the print() function to actually get something out of your code)

Events is a major concept and is the basis for most everything in the UI. Once you want to do things dynamically (as opposed to running the code once to remove some things, add some things, change some things) you're gonna have to deal with events. Absolutely everything that happens in the UI (except for certain animation-like things like cast bars) is driven by events. You've got events for chat messages coming in, spells being cast, items being looted, players joining your raid, everything. These are referred to simply as events. For the purposes of this conversation we can call them global events. They will always happen and nothing can change that. They also don't actually do anything by themselves. That's what the UI does. The UI (both the default and addons) listen for these events and act upon them. If nothing were to listen to these events, your UI would literally just be a picture. (note that the UI is distinct from the actual game world)
For a list of events, see http://wowprogramming.com/docs/events

There's another type of events that aren't really referred to as events. Sometimes frame scripts, or possibly frame events. These are frame (frame is often used as a generic term to refer to any object type such as frame, button, message frame, scrollframe, etc) "events" such as OnClick, OnScroll, OnShow, OnEvent etc. The OnEvent is the frame script that fires when an event that you're listening to triggers, and indeed this means that listening to events requires a frame. The rest of the frame scripts are mostly relevant once you start making visible stuff. Frames by themselves are only objects and has no visible elements. Textures and font strings (these two are sometimes referred to as regions and must be attached to a frame, unlike frames which can be "independent") are the only visible elements; until you start adding those, there's no telling that a frame exists by looking at the screen.

Links to global WoW API and "frame API".
http://wowprogramming.com/docs/api_categories
http://wowprogramming.com/docs/widgets
Wowpedia also has some stuff, but it's not as neatly organised, imo.
http://wowpedia.org/Portal:Interface_customization

One thing I forgot to mention that you'll definitely want to do is extracting the default UI.
http://wowpedia.org/Viewing_Blizzard%27s_interface_code
This will let you see how the default UI is built. It's built in the same way as regular addons, only they have access to a few things related to spell casting and targeting. More importantly, it'll let you eventually figure out how to modify it as you desire. That being said, their code is no easier to understand and learn from than any regular semi advanced addon. Also note that they don't always code the "best" possible way, so you shouldn't go thinking that their code automatically is perfect. (although it's generally okay)
__________________
Grab your sword and fight the Horde!

Last edited by Lombra : 06-28-14 at 05:37 AM.
  Reply With Quote
06-28-14, 05:36 AM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Here's an actual example that uses an event to react to your acquiring a new target:
Code:
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:SetScript("OnEvent", function(self, event, ...)
	if UnitExists("target") then -- this event also fires when you lose your target
		print("My new target is "..UnitName("target"))
	else
		print("I lost my target")
	end
end)
The basic frame type "Frame" is often used when all you want to do is use events, as it's the simplest frame type that can do this. Also there is no reason to specify a name or a parent for the frame since it's not going to be shown on screen.

The function that you pass to SetScript as your handler for "OnEvent"s will run every time that an event happens, that your frame is "listening to". If you don't register any events, it will never run.

As a final note, once you know what you want to do, even if you have no idea how to do it, it's a good idea to ask specific questions.
__________________
Grab your sword and fight the Horde!

Last edited by Lombra : 06-28-14 at 05:43 AM.
  Reply With Quote
07-02-14, 06:32 AM   #8
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
Thanks, your help is appreciated. Have a banana :3
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do i run my code?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off