MMOMinion

Full Version: Problem with API Sample #1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I hate to be that guy, but I'm having an issue with copy/pasting the sample#1 found at https://github.com/MMOMinion/FFXIVMinion...ample-%231

I copy/paste exactly as it is, and I get an error failed with
Code:
[string "D:\mmominion\bot\LuaMods\/test/yourmodulename.lua"]:4: unexpected symbol near '.'
Looking at line 4, I don't see what on earth could be causing this:
Code:
local mymodule.running = false

Can I get some help for the dummy?
The Sample 1 code is correct. I bet there's some invisible character in your Lua code. May I know what editor you're using?
Using Notepad++ - typically it always shows any character.

Not only that, but I did a direct copy/paste from the <code> section of the page so if there's no hidden character in the code, it should work straight up.
Need the rest too you know.
Just got it working.

I removed 'local' from the start of line 4 and 5, and it now loads.

Any reason why setting it as local would break it?
Haha yes, fire the person who did that. Unless I'm mistaken you can't create a local variable in the global namespace.
Don't mean to whip a dead horse but there seems to be a couple things more wrong with the sample Peep

Player.health.current seems to throw an error. Player.hp.current does report the correct number, however, I cannot get it to report it to the HP: field.

Below is a snippet I've taken out of the sample (with slight edit). d(Player.hp.current) reports to the console perfectly, however the hpvalue = tostring(Player.hp.current) line doesn't actually report it to the HP: field.

Code:
-- The Mainloop function, gets called all the time by FFXIVMinion:
function mymodule.OnUpdateHandler( Event, ticks )
    if ( mymodule.running and ticks - mymodule.lastticks > 500 ) then
        mymodule.lastticks = ticks
-- if the player is alive, set the current HP value into the new field of our created Window:
         if (Player.alive) then
            d(Player.hp.current)
            hpvalue = tostring(Player.hp.current)
         end
    end        
end

Also, I find that the GUI_NewWindow() function seems to have issues regarding window size and location, and that I need to use GUI_SizeWindow() to accurately display the window. Is this a known issue, or just me breaking stuff?

Normally when I want to pick up a new language quickly I take a working sample and break it to see what happens, but it seems I'm try to accomplish the opposite this time :P

Lastly, I appreciate the help so far in guiding me, it's appreciated!

Nevermind, figured it out. Seems that the window doesn't like displaying fields that are not part of a group. The code below is a 100% functioning "Sample #1". Please stick this up in place of the current one :)

Code:
-- Create a new table for our code:
mymodule= { }
-- Some local variables we use in our module:
mymodule.running = false
mymodule.lastticks = 0
mymodule.hpvalue = "0"

-- Initializing function, we create a new Window for our module that has 1 button and 1 field to display data:
function mymodule.ModuleInit()
    GUI_NewWindow("MyNewWindow",500,50,250,170);
    GUI_NewButton("MyNewWindow","Toggle","MYMODULE.TOGGLE");
    GUI_NewField("MyNewWindow","HP:","hpvalue","HitPoints"); -- In order to display the value of this field, it must be a part of a group ("HitPoints").
    GUI_SizeWindow("MyNewWindow",250,200) -- This line currently required in order to properly resize and display the window. GUI_NewWindow is a little broken right now.
end

-- The function that gets called when the button is pressed:
function mymodule.ToggleRun()
    mymodule.running = not mymodule.running
end

-- The Mainloop function, gets called all the time by FFXIVMinion:
function mymodule.OnUpdateHandler( Event, ticks )
    if ( mymodule.running and ticks - mymodule.lastticks > 500 ) then
        mymodule.lastticks = ticks
-- if the player is alive, set the current HP value into the new field of our created Window:
         if (Player.alive) then
            hpvalue = tonumber(Player.hp.current)
         end
    end        
end

-- Registering the Events
RegisterEventHandler("Gameloop.Update",mymodule.OnUpdateHandler) -- the normal pulse from the gameloop
RegisterEventHandler("MYMODULE.TOGGLE", mymodule.ToggleRun) -- the function that gets called when our button is pressed
RegisterEventHandler("Module.Initalize",mymodule.ModuleInit) -- the initialization function, gets called only once at startup of the game

Now, on to something more useful!