Array element from lua - lua

I'm making a fivem server. But when i tru to pick the job.grade.name he says No grades.
QBShared.Jobs = {
["unemployed"] = {
label = "Werkloos",
grades = {
[0] = {
name = 'Werkloos',
payment = 10,
},
},
defaultDuty = true,
},
["police"] = {
label = "Politie",
grades = {
[0] = {
name = "Politie - Student", **Want to pick this**
payment = 200,
},
[1] = {
name = 'Aspirant',
payment = 300,
},
[2] = {
name = 'Agent',
payment = 400,
},
[3] = {
name = 'Hoofd Agent',
payment = 400,
},
[4] = {
name = 'Brigadier',
payment = 400,
},
[5] = {
name = 'Inspecteur',
payment = 400,
},
[6] = {
name = 'Hoofd Inspecteur',
payment = 400,
},
[7] = {
name = 'Commissaris',
payment = 400,
},
[8] = {
name = 'Hoofd Commissaris',
payment = 400,
},
[9] = {
name = 'Eerste Hoofd Commissaris',
isboss = true,
payment = 400,
},
},
defaultDuty = true,
So people can type /baan and then the see Baan: Politie
What i want is The must see Baan: Politie - Politie Student
QBCore.Commands.Add("baan", "Kijk wat je baan is", {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
TriggerClientEvent('chatMessage', source, "SYSTEM", "warning", "Baan: "..Player.PlayerData.job.label .. ' - ' ..Player.PlayerData.job.grade.name)
end)
Someone can help me? Because i want to learn more about lua but dont get this to work..

'Jobs' needs a string key to access it
and 'grades' needs a numerical index
Player .PlayerData .Jobs [job] .grades [grade] .name
TriggerClientEvent('chatMessage', source, "SYSTEM", "warning", "Baan: "..Player.PlayerData.job.label .. ' - ' ..Player.PlayerData.Jobs[job].grades[grade].name)
I'm assuming that somehow within your game engine, these values get parsed into PlayerData. That'll depend on the functions contained within fivem, and that you've used them properly. Otherwise, to access the raw table data, it's more like this:
print( QBShared.Jobs['police'].label )
Politie
print( QBShared.Jobs['police'].grades[0].name )
Politie - Student
print( QBShared.Jobs['police'].grades[0].payment )
200
if the game rearranges those during import into PlayerData, it might be
Player.PlayerData[job][grade].name
but it's very likely it remains in the original syntax illustrated above.

Related

FiveM client lua. Problem with shops point

I have a problem with dots, when you enter a clothing store or a barbershop, the menu opens and works well. But after that, anywhere on the map, when you press E, the menu of a clothing store or a barbershop opens.
Here is the code itself, I myself do not know what the problem is there.
QBCore = exports['qb-core']:GetCoreObject()
local LastZone = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local hasAlreadyEnteredMarker = false
local allMyOutfits = {}
local isPurchaseSuccessful = false
local PlayerData = {}
-- Net Events
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.TriggerCallback('fivem-appearance:getPlayerSkin', function(appearance)
exports['fivem-appearance']:setPlayerAppearance(appearance)
PlayerData = QBCore.Functions.GetPlayerData()
if Config.Debug then -- This will detect if the player model is set as "player_zero" aka michael. Will then set the character as a freemode ped based on gender.
Wait(5000)
if GetEntityModel(PlayerPedId()) == `player_zero` then
print('Player detected as "player_zero", Starting CreateFirstCharacter event')
TriggerEvent('qb-clothes:client:CreateFirstCharacter')
end
end
end)
end)
RegisterNetEvent('qb-clothes:client:CreateFirstCharacter', function() -- Event renamed so you dont need to change anything for this to work... hopefully....
QBCore.Functions.GetPlayerData(function(PlayerData)
local skin = 'mp_m_freemode_01'
if PlayerData.charinfo.gender == 1 then
skin = "mp_f_freemode_01"
end
exports['fivem-appearance']:setPlayerModel(skin)
local config = {
ped = false,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
}
exports['fivem-appearance']:setPlayerAppearance(appearance)
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
if (appearance) then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
else
print('Canceled')
end
end, config)
end)
end, false)
AddEventHandler('fivem-appearance:hasExitedMarker', function(zone)
CurrentAction = nil
end)
RegisterNetEvent('fivem-appearance:clothingShop', function()
exports['qb-menu']:openMenu({
{
header = "👚 | Clothing Store Options",
isMenuHeader = true, -- Set to true to make a nonclickable title
},
{
header = "Buy Clothing - $"..Config.Money,
txt = "Pick from a wide range of items to wear",
params = {
event = "fivem-appearance:clothingMenu",
}
},
{
header = "Change Outfit",
txt = "Pick from any of your currently saved outfits",
params = {
event = "fivem-appearance:pickNewOutfit",
args = {
number = 1,
id = 2
}
}
},
{
header = "Save New Outfit",
txt = "Save a new outfit you can use later on",
params = {
event = "fivem-appearance:saveOutfit",
}
},
{
header = "Delete Outfit",
txt = "Yeah... We didnt like that one either",
params = {
event = "fivem-appearance:deleteOutfitMenu",
args = {
number = 1,
id = 2
}
}
},
})
end)
RegisterNetEvent('fivem-appearance:pickNewOutfit', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local outfitMenu = {
{
header = '< Go Back',
params = {
event = 'fivem-appearance:clothingShop'
}
}
}
for i=1, #allMyOutfits, 1 do
outfitMenu[#outfitMenu + 1] = {
header = allMyOutfits[i].name,
params = {
event = 'fivem-appearance:setOutfit',
args = {
-- number = (1 + i),
ped = allMyOutfits[i].pedModel,
components = allMyOutfits[i].pedComponents,
props = allMyOutfits[i].pedProps
}
}
}
end
exports['qb-menu']:openMenu(outfitMenu)
end)
RegisterNetEvent('fivem-appearance:getOutfits', function()
TriggerServerEvent('fivem-appearance:getOutfits')
end)
RegisterNetEvent('fivem-appearance:sendOutfits', function(myOutfits)
local Outfits = {}
for i=1, #myOutfits, 1 do
table.insert(Outfits, {id = myOutfits[i].id, name = myOutfits[i].name, pedModel = myOutfits[i].ped, pedComponents = myOutfits[i].components, pedProps = myOutfits[i].props})
end
allMyOutfits = Outfits
end)
RegisterNetEvent('fivem-appearance:setOutfit', function(data)
local pedModel = data.ped
local pedComponents = data.components
local pedProps = data.props
local playerPed = PlayerPedId()
local currentPedModel = exports['fivem-appearance']:getPedModel(playerPed)
if currentPedModel ~= pedModel then
exports['fivem-appearance']:setPlayerModel(pedModel)
Wait(500)
playerPed = PlayerPedId()
exports['fivem-appearance']:setPedComponents(playerPed, pedComponents)
exports['fivem-appearance']:setPedProps(playerPed, pedProps)
local appearance = exports['fivem-appearance']:getPedAppearance(playerPed)
TriggerServerEvent('fivem-appearance:save', appearance)
else
exports['fivem-appearance']:setPedComponents(playerPed, pedComponents)
exports['fivem-appearance']:setPedProps(playerPed, pedProps)
local appearance = exports['fivem-appearance']:getPedAppearance(playerPed)
TriggerServerEvent('fivem-appearance:save', appearance)
end
-- TriggerEvent('fivem-appearance:clothingShop')
end)
RegisterNetEvent('fivem-appearance:saveOutfit', function()
local keyboard = exports['qb-input']:ShowInput({
header = "Name your outfit",
submitText = "Create Outfit",
inputs = {
{
text = "Outfit Name",
name = "input",
type = "text",
isRequired = true
},
},
})
if keyboard ~= nil then
local playerPed = PlayerPedId()
local pedModel = exports['fivem-appearance']:getPedModel(playerPed)
local pedComponents = exports['fivem-appearance']:getPedComponents(playerPed)
local pedProps = exports['fivem-appearance']:getPedProps(playerPed)
Wait(500)
TriggerServerEvent('fivem-appearance:saveOutfit', keyboard.input, pedModel, pedComponents, pedProps)
QBCore.Functions.Notify('Outfit '..keyboard.input.. ' has been saved', 'success')
end
end)
RegisterNetEvent('fivem-appearance:deleteOutfitMenu', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local DeleteMenu = {
{
header = '< Go Back',
params = {
event = 'fivem-appearance:clothingShop'
}
}
}
for i=1, #allMyOutfits, 1 do
DeleteMenu[#DeleteMenu + 1] = {
header = 'Delete "'..allMyOutfits[i].name..'"',
txt = 'You will never be able to get this back!',
params = {
event = 'fivem-appearance:deleteOutfit',
args = allMyOutfits[i].id
}
}
end
exports['qb-menu']:openMenu(DeleteMenu)
end)
RegisterNetEvent('fivem-appearance:deleteOutfit', function(id)
TriggerServerEvent('fivem-appearance:deleteOutfit', id)
-- TriggerEvent('fivem-appearance:clothingShop')
QBCore.Functions.Notify('Outfit Deleted', 'error')
end)
RegisterNetEvent("fivem-appearance:purchase", function(bool)
isPurchaseSuccessful = bool
end)
RegisterNetEvent('fivem-appearance:clothingMenu', function()
TriggerServerEvent('fivem-appearances:buyclothing')
Wait(500)
if isPurchaseSuccessful then
local config = {
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = false,
components = true,
props = true
}
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
if appearance then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end
end)
RegisterNetEvent('fivem-appearance:barberMenu', function()
local config = {
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = true,
components = false,
props = false
}
exports['fivem-appearance']:startPlayerCustomization(function (appearance)
if appearance then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end)
-- Backwords Events so you dont need to replace these
RegisterNetEvent('qb-clothing:client:openMenu', function() -- Admin Menu clothing event
Wait(500)
local config = {
ped = true,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true
}
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
if appearance then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end)
RegisterNetEvent('qb-clothing:client:openOutfitMenu', function() -- Name is so that you dont have to replace the event, Used in Appartments, Bossmenu, etc...
exports['qb-menu']:openMenu({
{
header = "👔 | Outfit Options",
isMenuHeader = true, -- Set to true to make a nonclickable title
},
{
header = "Change Outfit",
txt = "Pick from any of your currently saved outfits",
params = {
event = "fivem-appearance:pickNewOutfitApp",
args = {
number = 1,
id = 2
}
}
},
{
header = "Save New Outfit",
txt = "Save a new outfit you can use later on",
params = {
event = "fivem-appearance:saveOutfit",
}
},
{
header = "Delete Outfit",
txt = "Yeah... We didnt like that one either",
params = {
event = "fivem-appearance:deleteOutfitMenu",
args = {
number = 1,
id = 2
}
}
},
})
end)
RegisterNetEvent('fivem-appearance:pickNewOutfitApp', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local outfitMenu = {
{
header = '< Go Back',
params = {
event = 'qb-clothing:client:openOutfitMenu'
}
}
}
for i=1, #allMyOutfits, 1 do
outfitMenu[#outfitMenu + 1] = {
header = allMyOutfits[i].name,
params = {
event = 'fivem-appearance:setOutfit',
args = {
-- number = (1 + i),
ped = allMyOutfits[i].pedModel,
components = allMyOutfits[i].pedComponents,
props = allMyOutfits[i].pedProps
}
}
}
end
exports['qb-menu']:openMenu(outfitMenu)
end)
RegisterNetEvent('fivem-appearance:deleteOutfitMenuApp', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local DeleteMenu = {
{
header = '< Go Back',
params = {
event = 'fivem-appearance:clothingShop'
}
}
}
for i=1, #allMyOutfits, 1 do
DeleteMenu[#DeleteMenu + 1] = {
header = 'Delete "'..allMyOutfits[i].name..'"',
txt = 'You will never be able to get this back!',
params = {
event = 'fivem-appearance:deleteOutfit',
args = allMyOutfits[i].id
}
}
end
exports['qb-menu']:openMenu(DeleteMenu)
end)
-- Theads
CreateThread(function()
while true do
Wait(0)
if CurrentAction ~= nil then
if IsControlPressed(1, 38) then
Wait(500)
if CurrentAction == 'clothingMenu' then
TriggerEvent("fivem-appearance:clothingShop")
end
if CurrentAction == 'barberMenu' then
TriggerEvent("fivem-appearance:barberMenu")
end
end
end
end
end)
CreateThread(function()
for k,v in ipairs(Config.BarberShops) do
local blip = AddBlipForCoord(v)
SetBlipSprite (blip, 71)
-- SetBlipColour (blip, 47)
SetBlipScale (blip, 0.7)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName('Barber Shop')
EndTextCommandSetBlipName(blip)
end
for k,v in ipairs(Config.ClothingShops) do
local data = v
if data.blip == true then
local blip = AddBlipForCoord(data.coords)
SetBlipSprite (blip, 73)
-- SetBlipColour (blip, 47)
SetBlipScale (blip, 0.7)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName('Clothing Store')
EndTextCommandSetBlipName(blip)
end
end
end)
CreateThread(function()
while true do
local playerCoords, isInClothingShop, isInPDPresets, isInBarberShop, currentZone, letSleep = GetEntityCoords(PlayerPedId()), false, false, nil, true
local sleep = 2000
for k,v in pairs(Config.ClothingShops) do
local data = v
local distance = #(playerCoords - data.coords)
if distance < Config.DrawDistance then
sleep = 500
if distance < data.MarkerSize.x then
isInClothingShop, currentZone = true, k
end
end
end
for k,v in pairs(Config.BarberShops) do
local distance = #(playerCoords - v)
if distance < Config.DrawDistance then
sleep = 500
if distance < Config.MarkerSize.x then
isInBarberShop, currentZone = true, k
end
end
end
if (isInClothingShop and not hasAlreadyEnteredMarker) or (isInClothingShop and LastZone ~= currentZone) then
hasAlreadyEnteredMarker, LastZone = true, currentZone
CurrentAction = 'clothingMenu'
exports['qb-drawtext']:DrawText('[E] Clothing Menu','left')
end
if (isInBarberShop and not hasAlreadyEnteredMarker) or (isInBarberShop and LastZone ~= currentZone) then
hasAlreadyEnteredMarker, LastZone = true, currentZone
CurrentAction = 'barberMenu'
exports['qb-drawtext']:DrawText('[E] Barber Menu','left')
end
if not isInClothingShop and not isInBarberShop and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
sleep = 0
TriggerEvent('fivem-appearance:hasExitedMarker', LastZone)
exports['qb-drawtext']:HideText()
end
Wait(sleep)
end
end)
-- Command(s)
RegisterCommand('reloadskin', function()
local playerPed = PlayerPedId()
local maxhealth = GetEntityMaxHealth(playerPed)
local health = GetEntityHealth(playerPed)
QBCore.Functions.TriggerCallback('fivem-appearance:getPlayerSkin', function(appearance)
exports['fivem-appearance']:setPlayerAppearance(appearance)
end)
for k, v in pairs(GetGamePool('CObject')) do
if IsEntityAttachedToEntity(PlayerPedId(), v) then
SetEntityAsMissionEntity(v, true, true)
DeleteObject(v)
DeleteEntity(v)
end
SetPedMaxHealth(PlayerId(), maxhealth)
Citizen.Wait(1000) -- Safety Delay
SetEntityHealth(PlayerPedId(), health)
end
end)
-- Testing Command
RegisterCommand('clothingmenu', function()
local config = {
ped = true,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
}
exports['fivem-appearance']:startPlayerCustomization(function (appearance)
if (appearance) then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end, false)
I tried to set the boundaries of the vectors, it did not help. Tried to find the error but couldn't...
The problem is that the CurrentAction variable is never being reset to nil, so the thread you started to monitor for that keypress continues to "react" to it with the last visited store.
The way the code is written, it appears as though it is meant to be reset to nil only when the when hasExitedMarker function is triggered, but you only trigger this in one place - and it is only conditionally run only if hasAlreadyEnteredMarker is set to true when a shop is detected as being exited. I have a feeling that variable is not being properly maintained.
You can see how this quickly turns into a daisy-chain of state that must be maintained "just so".
Without undergoing a massive debugging session on your behalf, I can only suggest you debug these variables by outputting them to the screen, and watching for when they are set and properly unset (or not).
Higher level advice might be to add whatever routine you use to detect entry/exit into barber/clothing shops to a standalone function you can call directly from the keypress event handler, and skip handling it if you are not in the expected location. This won't solve your original problem of your application state falling into disrepair, but it gives you a chance to "fix" your state on keypress if it turns out you are handling it when you shouldn't be.

Inherit LUA Table with variables from Class with setmetatable

I'm new to the concept of "faking" OOP in lua with metatables, indexes and OOP in general.
I'm trying to create an instance from an Object in LUA which use variables in the table, so that every instance have its own values. The Fighter model seams pretty common, so I'm trying to explain :-)
FIGHTER = {
["id"] = "Fighter",
["params"] = {
["route"] =
{
["points"] =
{
[1] =
{
["x"] = wp01x,
["y"] = wp01y,
["speed"] = fighterSpeed,
["task"] =
{
["id"] = "ComboTask",
},
},
},
},
},
}
function FIGHTER:new(t)
t = t or {}
setmetatable(t,self)
self.__index = self
return t
end
local wp01x = 0.38746345345
local wp01y = 1.39876268723
local fighterSpeed = 123
local test = FIGHTER:new({FIGHTER})
When the table is created, x, y, speed are nil (so the entries missing on construction).
Passing the values in the Constructor with something like
self.["Mission"].["params"].["route"].["points"].[1].["speed"] = 99
don't work either.
What would be best practice to create such instances? Use some preset values and clone the table later?
I correct your version a little bit and hope it opens your eyes...
FIGHTER = {
["id"] = "Fighter",
["params"] = {
["route"] =
{
["points"] =
{
[1] =
{
["x"] = 0,
["y"] = 0,
["speed"] = 0,
["task"] =
{
["id"] = "ComboTask",
},
},
},
},
},
}
function FIGHTER:new(t, wpx, wpy, speed)
t = t or {id = "Fighter", params = {route = {points = {[1] = {x = wpx, y = wpy, fighterSpeed = speed, task = {id = "ComboTask"}}}}}}
setmetatable(t,self)
self.__index = self
return t
end
local wp01x = 0.38746345345
local wp01y = 1.39876268723
local fighterSpeed = 123
-- The t = t or >>{...}<< case
test = FIGHTER:new(_, wp01x, wp01y, fighterSpeed)
-- The t = >>t<< case
test = FIGHTER:new({id = "Fighter", params = {route = {points = {[1] = {x = wp01x, y = wp01y, fighterSpeed = fighterSpeed, task = {id = "ComboTask"}}}}}})

Trying to insert table into table without creating a new table when saving to a file

I am attempting to add a "recipe" (Table) into a file for future look up.
My issue is that when I upload the data into the file, it creates a new table and does not insert into the "Main" table as a nested table. This causes issues when trying to search for a "recipe" within the main "recipe book".
The following is the code for this section of the project. The issue I believe is near the uploading of the data to a file but I am stumped. Can someone explain what the heck I am doing wrong?
When I run the code a second time it adds in the information into the main table without issue, but it adds it under the original table.
When I run the code any more times it just adds in a new table.
Code:
--recursive search in--recursive search into tables
local Deep = require "DeepPrint"
--Working from the following info
--http://www.computercraft.info/forums2/index.php?/topic/23076-crafting-api-learn-recipes/
--the solution found: https://stackoverflow.com/questions/19299162/lua-table-expected-got-nilo
--variables--
--data holding place for recipes
Recipes = {}
--Crafting Grid
grid = {1,2,3,5,6,7,9,10,11};
--check for recipe book, if exists then read the data
local readRecipe = fs.open("recipeBook.lua","r")
if readRecipe == nil then
print("recipe book not found")
else
recipeList = readRecipe.readAll()
readRecipe.close()
ok, Recipes = pcall(textutils.unserialize, recipeList)
if not ok then
return false, recipeList
end
if type(Recipes) ~= "table" then
print("Main table not found, creating base table")
Recipes = {}
end
end
if readRecipe == nil then
print("recipe book not found")
else
recipeList = readRecipe.readAll()
readRecipe.close()
ok, Recipes = pcall(textutils.unserialize, recipeList)
if not ok then
return false, recipeList
end
if type(Recipes) ~= "table" then
print("Main table not found, creating base table")
Recipes = {}
end
end
--get recipe location and details to push into recipeBook.lua
itemLayout = {}
for key,value in pairs(grid) do
turtle.select(value)
if turtle.getItemDetail() then
details = turtle.getItemDetail()
table.insert(itemLayout,{
name = details.name,
count = details.count,
location = value
})
end
end
--craft item to get the name of crafted item
turtle.select(16)
turtle.craft()
itemMade = turtle.getItemDetail()
--check if table exists and if not creates a table
if not Recipes[itemMade.name] then
print("didnt find the table for item, creating new table")
Recipes[itemMade.name] = {}
else
print("found recipe")
end
--add in info into main product table
Recipes[itemMade.name]["components"] = itemLayout
Recipes[itemMade.name]["quantityMade"] = itemMade.count
--add recipe to list
local ok, str = pcall(textutils.serialize, Recipes)
if not ok then
return false, str
else
book = fs.open("recipeBook.lua","a")
book.writeLine(str)
book.close()
end
Results in the following type of table
{
[ "minecraft:crafting_table" ] = {
components = {
{
location = 1,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 2,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 5,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 6,
name = "minecraft:oak_planks",
count = 1,
},
},
quantityMade = 1,
},
}
{
[ "minecraft:oak_button" ] = {
components = {
{
location = 1,
name = "minecraft:oak_planks",
count = 1,
},
},
quantityMade = 1,
},
[ "minecraft:crafting_table" ] = {
components = {
{
location = 1,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 2,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 5,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 6,
name = "minecraft:oak_planks",
count = 1,
},
},
quantityMade = 1,
},
}
{
[ "minecraft:oak_button" ] = {
components = {
{
location = 1,
name = "minecraft:oak_planks",
count = 1,
},
},
quantityMade = 1,
},
}
{
[ "minecraft:oak_pressure_plate" ] = {
components = {
{
location = 1,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 2,
name = "minecraft:oak_planks",
count = 1,
},
},
quantityMade = 1,
},
}
{
[ "minecraft:crafting_table" ] = {
components = {
{
location = 1,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 2,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 5,
name = "minecraft:oak_planks",
count = 1,
},
{
location = 6,
name = "minecraft:oak_planks",
count = 1,
},
},
quantityMade = 1,
},
}
I found the issue to this.
is due to the fact I had it appending to the file and not writing when uploading the information back to the file.
2)The second was the pointless array at the beginning with the variable Recipes, before even starting to gather the info from the file. This caused the upload to have another nest that wasn't needed

Assign to child model items from controller

I'm trying to assign values to items within a child model but don't seem to be able to do this.
var model = new WOLFormViewModel
{
LastS= 0,
Start = sitecustomattributes.Start,
End = sitecustomattributes.End,
PrimeSel = false,
ADFSel = false,
SupplementarySel = false,
BondSel = false,
SheetNo = 0,
EntryOneModel.Code = 1234
};
EntryOneModel is a public class within WOLFormViewModel.
Does anyone know why I can't assign data to EntryOneModel.Code = 1234?
var model = new WOLFormViewModel
{
LastS= 0,
Start = sitecustomattributes.Start,
End = sitecustomattributes.End,
PrimeSel = false,
ADFSel = false,
SupplementarySel = false,
BondSel = false,
SheetNo = 0,
EntryOne = new EntryOneModel() { Code = 1234 )
};

Send mail with attachments from an app built with Corona on iOS 10.2.1

I need to send an email with attachments from my app built with Corona SDK on an iOS device with 10.2.1. I had at one time built a Corona app that had the ability to send an email with attachments and it worked just fine. Now, as of iOS 10.2.1, it doesn't seem to work and I can't tell if it's because I'm writing the code wrong or if the native.showPopup is not compatible with iOS 10.2.1.
I am using Corona build 2017.3059.
Also, I have checked my device (an iPhone 6) with native.canShowPopup( "mail" ) and it indicated that the mail pop up feature is available on the device.
Below is the code I'm using.
local widget = require( "widget" )
-- Function to handle button event
local function sendMail( event )
if ( "ended" == event.phase ) then
if ( native.canShowPopup( "mail" ) ) then
native.showAlert( "Alert!", "Mail IS available on this device", { "OK" } )
local options =
{
to = { "john.doe#somewhere.com", "jane.doe#somewhere.com" },
cc = { "john.smith#somewhere.com", "jane.smith#somewhere.com" },
subject = "My High Score",
isBodyHtml = true,
body = "<html><body>I scored over <b>9000</b>!!! Can you do better?</body></html>"
}
native.showPopup( "mail", options )
else
native.showAlert( "Alert!", "Mail NOT available on this device", { "OK" } )
end
end
end
-- Create the widget
local mailButton = widget.newButton(
{
label = "Mail",
fontSize = 64,
onRelease = sendMail, -- this is my function to send mail
labelColor = { default={ 1, 1, 1 } },
labelAlign = "center",
emboss = false,
shape = "roundedRect",
width = 200,
height = 100,
cornerRadius = 13,
fillColor = { default={1,0,0}, over={0,1,1} },
strokeColor = { default={1,1,1}, over={1,1,1} },
strokeWidth = 4
}
)
mailButton.x = display.contentCenterX
mailButton.y = display.contentCenterY
I was able to get this working. There were actually two issues:
1) The email accounts on my device were problematic for some reason.
For some reason, I'm not sure why, I had to delete my email accounts and reinstate them and that seemed to solve the problem. It was a pretty common configuration I feel like, I had two Gmail accounts installed on the Apple iOS Mail app. But deleting them and reinstating them did the trick
2) You can't trigger alert boxes before triggering an email
Before my code would work properly, I had to get rid of the:
native.showAlert( "Alert!", "Mail IS available on this device", { "OK" } )
So the working code is:
local widget = require( "widget" )
-- Function to handle button event
local function sendMail( event )
if ( "ended" == event.phase ) then
if ( native.canShowPopup( "mail" ) ) then
local options =
{
to = { "john.doe#somewhere.com", "jane.doe#somewhere.com" },
cc = { "john.smith#somewhere.com", "jane.smith#somewhere.com" },
subject = "My High Score",
isBodyHtml = true,
body = "<html><body>I scored over <b>9000</b>!!! Can you do better?</body></html>"
}
native.showPopup( "mail", options )
else
native.showAlert( "Alert!", "Mail NOT available on this device", { "OK" } )
end
end
end
-- Create the widget
local mailButton = widget.newButton(
{
label = "Mail",
fontSize = 64,
onRelease = sendMail, -- this is my function to send mail
labelColor = { default={ 1, 1, 1 } },
labelAlign = "center",
emboss = false,
shape = "roundedRect",
width = 200,
height = 100,
cornerRadius = 13,
fillColor = { default={1,0,0}, over={0,1,1} },
strokeColor = { default={1,1,1}, over={1,1,1} },
strokeWidth = 4
}
)
mailButton.x = display.contentCenterX
mailButton.y = display.contentCenterY

Resources