Assign to child model items from controller - asp.net-mvc

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 )
};

Related

can someone help me figure out why my script automatically executes without out me pressing the button?

local OrionLib = loadstring(game:HttpGet(('https://raw.githubusercontent.com/shlexware/Orion/main/source')))()
local Window = OrionLib:MakeWindow({Name = "BoxHub", HidePremium = false, SaveConfig = true, ConfigFolder = "OrionTest"})
---Values
getgenv().AutoFarm = true
--tabs
local MainTab = Window:MakeTab({
Name = "Main",
Icon = "rbxassetid://4483345998",
PremiumOnly = false
})
--toggels
MainTab:AddToggle({
Name = "AutoFarm",
Default = false,
Callback = function(Value)
wait(1)
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(-118.933174, 3.50129104, 63.7992935, -0.99859041, -2.3044068e-08, -0.0530771464, -2.18308767e-08, 1, -2.34369075e-08, 0.0530771464, -2.22451497e-08, -0.99859041)
wait(1)
game:GetService("ReplicatedStorage").Strength_Exercises.Squat1:FireServer()
wait(17)
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(-144.613525, 3.50129104, -52.2876129, -0.0295129567, -3.152`48556e-08, 0.999564409, -2.02664463e-08, 1, 3.09402104e-08, -0.999564409, -1.93444816e-08, -0.0295129567)`
wait(1)
game:GetService("ReplicatedStorage").Strength_Exercises.Speed_Bag2:FireServer()
wait(3)
end
})
i tried doing a function like this
function getgenv().AutoFarm
AutoFarm() = Value
and it just made the toggle button not work`

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

Array element from 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.

How do I return multiple values in a function return in lua

I am trying to return GetUserGroup into multiple values but it only returns into 1 i tried using the for statement but did not work and I don't want to do ply:GetUserGroup() == "owner" or ply:GetUserGroup() == "superadmin" that is the only way of fixing the problem but its going to be a long line and I cant have that
This is the darkrp addentity code:
DarkRP.createEntity("Money printer", {
ent = "money_printer",
model = "models/props_c17/consolebox01a.mdl",
price = 1000,
cmd = "buymoneyprinter",
getMax = function(ply)
local limitRanks = {"odyssian", "tmod", "dmod", "dadmin", "admin", "superadmin", "co-owner", "owner"}
return ply:GetUserGroup() == limitRanks and 6 or 3
end,
})
You need to turn limitRanks into a hash table and check if the key is present in the return statement:
local limitRanks = {odyssian = true, tmod = true, dmod = true, dadmin = true,
admin = true, superadmin = true, ["co-owner"] = true, owner = true}
return limitRanks[ply:GetUserGroup()] and 6 or 3

Resources