blakepell / AvalonMudClient

A Windows MUD client written in C#/WPF for .NET 8.
Other
31 stars 7 forks source link

Lua errors on multiple entry #2

Closed blakepell closed 4 years ago

blakepell commented 4 years ago

The Lua engine is having exceptions when more than one script enter the engine at a time. Look into the MoonSharp documentation and see if either multiple instances need to be started up for async calls or if they need to be called in a different way. The exceptions can manifest with different exceptions. Examples: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

--> Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') --> Index was outside the bounds of the array. --> Object reference not set to an instance of an object. --> Unexpected type in table ctor : 0 --> Unexpected type in table ctor : 10 --> attempt to index a nil value --> attempt to index a number value

To test this I created an alias that executed a Lua script and then repeated in fast succession with the #repeat command.

Lua Alias (named test):

local data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local value = data[math.random(1, 10)]
local anotherVar = value * 5;
Cmd:Echo("Your value is " .. anotherVar)

Hash Command:

#repeat 50 test

blakepell commented 4 years ago

Lua was altered to create a new script object each time one is run which fixes the concurrent bugs that were occurring when async scripts would fire at the same time.