csharpissuetracker's People
csharpissuetracker's Issues
C# event bridge error
Happens when an arg == nil
[error] An error occurred while calling event SomeCoolEvent! System.NullReferenceException: Object reference not set to an instance of an object. at Onset.Server.Runtime.Bridge.CallEvent(IntPtr eventNamePtr, BridgedParam** args, Int32 count)
Unable to call imported function from the same package
Hi,
I have a problem with calling my own lua function from the C# server. Those functions are declared and exported in the same package as is my C# package. See below
lua
function HandleVehicleInteraction(vehicle, player, key, isCtrl, isAlt, isShift)
if (key ~= "U") then return end
if (GetPlayerVehicle(player) == 0) then
SetPlayerInVehicle(player, vehicle)
else
RemovePlayerFromVehicle(player)
end
end
AddFunctionExport("HandleVehicleInteraction", HandleVehicleInteraction)
AddEvent("OnPlayerJoin", function(player)
G_Package.API_Entity_PlayerMonitorKey(player, "U")
end)
AddEvent("OnPlayerSpawn", function(player)
local x, y, z = GetPlayerLocation(player)
x = x + 500
CreateVehicle(6, x, y, z)
end)
AddEvent("OnVehicleCreated", function(vehicle)
G_Package.API_Entity_AddVehicleInteraction(vehicle, "HandleVehicleInteraction")
end)
c#
[Export("API_Entity_AddVehicleInteraction")]
public static void AddVehicleInteraction(int vId, string callbackName)
{
var func = Framework.Instance.Interop.Import(Framework.Instance.Name, callbackName) ??
throw new ArgumentException($"Unable to import {callbackName} function");
FVehicle vehicle = Framework.GetVehicle(vId) ?? throw new ArgumentException($"No vehicle with id {vId}");
vehicle.AddInteraction((source, player, key, ctrl, alt, shift) =>
{
Framework.GetLogger().Script($"Calling veh interaction ({source.Id}, {player.Id}, {key}, {ctrl}, {alt}, {shift})");
func(source.Id, player.Id, key, ctrl, alt, shift);
});
}
This gives me the following log, followed by a server crash
It is worth mentioning that interactions are propagated through an event, when the player press the key (which is monitored client-side), a RemoteEvent is triggered, which propagate the interaction to the entity.
From what I can see, it seems the error occurs when calling the imported function, while it try to access to EventManager, but I'm not sure about that
Nested dictionary not working with lua
Hi,
there is a bug with nested dictionary not being sent back to lua, see below
C#
[Export("API_Inventory_GetContent")]
public static Dictionary<object, object>? GetInventoryContent(string id)
{
Logger logger = Framework.GetLogger();
Inventory? inv = Framework.GetInventory(id);
if (inv == null)
return null;
Dictionary<object, object> ret = new();
int i = 0;
foreach (ItemStack stack in inv.Items())
{
logger.Info($"GetContent, add item {stack.Meta.ReferenceName}, { stack.Amount }; i = { i }");
Dictionary<object, object> vals = new()
{
{"Reference_Name", stack.Meta.ReferenceName},
{"Amount", stack.Amount}
};
ret.Add(i++, vals);
}
return ret;
}
Lua
G_Package = ImportPackage(GetPackageName()) -- Need to reimport my package, because c# exported functions are not available
local function Log(player, message)
AddPlayerChat(player, message)
print(message)
end
AddCommand("test_inventory", function(player)
local uid = G_Package.create_inv(player)
G_Package.API_ItemMeta_RegisterItem("apple")
G_Package.API_ItemMeta_RegisterItem("water_bottle")
G_Package.API_Inventory_AddItemStack(uid, "apple", 2)
G_Package.API_Inventory_AddItemStack(uid, "water_bottle", 4)
G_Package.API_ItemMeta_SetAttribute("water_bottle", "thirst", 20)
G_Package.API_ItemMeta_SetAttribute("apple", "hunger", 5)
local content = G_Package.API_Inventory_GetContent(uid)
Log(player, dump_table(content))
end)
Then the console print the following message
Logs clearly display that I'm adding content to the dictionary
If I just serialize the item to JSON instead of using nested dictionary, then it works well
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.