Thread Tools Display Modes
04/25/14, 12:17 PM   #21
Fathis Ules
Thief Guild Master
 
Fathis Ules's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
ha yeah you use XML so you will need globals and a naming like MyAddonRollDice

or one good practice is to have a unique global aray named after your addon like MyAddon = {}

Lua Code:
  1. MyAddon = {}
  2.  
  3. function MyAddon.RollDice()
  4.     d("hello")
  5. end
  6.  
  7. function MyAddon.d()
  8.  
  9. end
  10.  
  11. function MyAddon.whatever()
  12.  
  13. end

So then you can call in your XML the MyAddon.RollDice()

You will be able directly call locals when you will experiment doing an UI without a single xml file, with API CreateControl, but easier to start with XML, at least you see the concept of local vs globals
  Reply With Quote
04/25/14, 12:45 PM   #22
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
Ok I fixed the name of the global function I'm using. Now you said to enter my code after LootDice:SetHandler( "OnMoveStop", function()
I'm not sure exactly what you mean. I have this so far.

Lua Code:
  1. function MyAddonRollDice()
  2.     local num = math.random(1,100)
  3.     return num
  4. end
  5.  
  6.  
  7. LootDice:SetHandler( "OnMoveStop", function()
  8.     local function OnAddOnLoaded(eventCode, LootDice)
  9.     if(LootDice == "<<LootDice>>") then
  10.         local savedVars = ZO_SavedVars:New(LootDice_SavedVariables, 1)
  11.     end
  12. end)
  13.  
  14. EVENT_MANAGER:RegisterForEvent("LootDice", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

I'm not sure if I move the function MyAddonRollDice into the LootDice:SetHandler or what. If you can could you copy the code and fix it so that I can see exactly where I'm messing up this also helps me understand a little better. I'm more of a visual learner and there are no youtube videos on eso lua yet. So I have been learning just lua. Things get more complicated when entering it into a game lol.
  Reply With Quote
04/25/14, 01:07 PM   #23
Fathis Ules
Thief Guild Master
 
Fathis Ules's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
When you write


Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("LootDice", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

the code is looking for a local function OnAddOnLoaded and your is not declared so it will never execute

you need to write the OnAddOnLoaded as any other local function outside the handler

Lua Code:
  1. local function OnAddOnLoaded(eventCode, addon)
  2.     if addon == "LootDice" then
  3.         LootDice_SavedVariables = { "lolilol", isAddOnEnabled = true} -- you don't really need the New() as long as you write ## SavedVariables: LootDice_SavedVariables in you toc .txt file, the variable is saved automatically
  4.         d("LootDice_SavedVariables.isAddOnEnabled = "..tostring(LootDice_SavedVariables.isAddOnEnabled))
  5.     end
  6. end

you don't really need the New() as long as you write ## SavedVariables: LootDice_SavedVariables in you toc .txt file, the variable is saved automatically when you declare it LootDice_SavedVariables = {} so anything you will create inside will be saved on disconnect or reloadui LootDice_SavedVariables.option1 LootDice_SavedVariables.option2 etc..

If you try the sample function I showed you and you hit /reloadui, you will see "lolilol" written in you savedvariable file and isAddOnEnabled ^^


Also no need to name MyAddonRollDice, when I wrote MyAddon that a sample to replace with the name of your addon, like LootDiceRollDice , LootDicePrint, LootDiceShow, etc etc so that the functions are globally identifiable to belong to the addon called LootDice

Last edited by Fathis Ules : 04/25/14 at 01:27 PM.
  Reply With Quote
04/28/14, 11:45 PM   #24
SpecialK
Join Date: Apr 2014
Posts: 6
Note this particular flavor of Lua is Havok Script that unfortunately uses the default C library not so random "rand()" function (default for a windows Lua build) at it's core.
It only has 15bits precision and has pretty bad pseudorandom properties.
It's too bad they didn't implement a nice 53bit RNG like LuaJit now has.

At any rate if you want a better RNG you might code one in pure Lua. Just keep in mind this Lua version uses doubles (64bit floats).
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Anyone Know the Lua for Random Numbers in ESO????

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