Lench Scripter Mod [Besiege v0.42]

#23
This was something that had to happen at some point. Thanks for making it !

Btw you mentioned you cannot activate things from Unity because they are not public. If it's just a matter of private members (properties / methods) you can still call them with reflection (with BindingFlags.NonPublic).
 
#24
hey, i'm having trouble trying to get my machine to move forward, it doesn't do anything when i press the assigned key, could somebody look at this and tell me what im doing wrong?

Code:
left_wheel = fb1882f9-8808-4727-8477-c5c628fb437b
right_wheel = f611a1c5-f9b2-4e79-b6de-646b2b0bed5a
direction = 1
speed = 0

besiege:setToggleMode(left_wheel, "AUTOMATIC", true)
besiege:setToggleMode(right_wheel, "AUTOMATIC", true)

function onUpdate()
    besiege:setSliderValue(left_wheel, "SPEED", speed)
    besiege:setSliderValue(right_wheel, "SPEED", speed)
    speed = 0
end

function onKeyHeld(key)
    if key == KeyCode.U then
        speed = 1
    end
end
thanks in advance
 

Lench

Active Member
#26
The block identifier is a string, so you have to put it in quotation marks like this:
Code:
left_wheel = 'fb1882f9-8808-4727-8477-c5c628fb437'
If you are ever in doubt why something's not working, press Ctrl+K to open the console. Any errors in your code will be logged there.
 

Lench

Active Member
#27
Big update v0.90:
  • Object-oriented approach to scripting - read more here.
  • No more key simulation for activating blocks - no more reliability issues, platform independence.
  • Added onFixedUpdate() function. Use if your script needs to be independent of your frame rate.
  • BREAKING SOME BACKWARDS COMPATIBILITY:
    • Removed getPitch(), getRoll(), getYaw(), getHeading() functions - use getEulerAngles() instead
    • Time from getTime() and getScaledTime() is now returned in seconds instead of milliseconds for consistency
 
#28
Hello and nice to see that someone's bothering to keep this mod alive.

I just downloaded and installed this and now when trying to use it I'm constantly getting the error messages "ArgumentException: Type cannot be null." and "BlockNotFoundException: Block WHEEL 1 not found." I've tried the example script, bumshat's code, and mine with same results. Is there something I'm missing?
 

Lench

Active Member
#29
I can't really tell what's wrong without looking into it, but the BlockNotFoundException only comes up when you're asking for a block that's not in your machine.

Are you sure the right script is executing? Your machine is saved and the script has the same name as your machine? The example script should definitely work. Try following the getting started guide on this page: "https://github.com/lench4991/LenchScripterMod/wiki/Getting-started

If that's not it, send me your .bsg and .lua files and I'll see if I can figure out what's wrong.
 
#30
Here's my console when running the example-script:

Script file: D:/Games/STEAM/steamapps/common/Besiege/Besiege_Data/Scripts/example-script.lua
ArgumentException: Type cannot be null.
-UnityEngine.Component.GetComponent (System.Type type)
-LenchScripterMod.Blocks.Block.Initialize (.BlockBehaviour bb)
-LenchScripterMod.Scripter.CreateBlock (.BlockBehaviour bb)
-LenchScripterMod.Scripter.InitializeSimulationBlockHandlers ()
-LenchScripterMod.Scripter.GetBlock (System.String blockId)
-LenchScripterMod.LuaMethodWrapper.getBlock (System.String blockId)
-LenchScripterMod.LuaMethodWrapper.setToggleMode (System.String blockId, System.String toggleName, Boolean value)
-System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
-Rethrow as LuaScriptException: A .NET exception occured in user-code
-NLua.Lua.ThrowExceptionFromError (Int32 oldTop)
-NLua.Lua.DoFile (System.String fileName)
-LenchScripterMod.Scripter.LoadLuaScript ()
-UnityEngine.Debug:LogException(Exception)
-LenchScripterMod.Scripter:LoadLuaScript()
-LenchScripterMod.Scripter:Update()
Script stopped

If it helps. It says something about a .NET exception in user-code?
 

Lench

Active Member
#31
Oh well, this seems to be a bug in my code. I think I know what's causing it. Thanks for noticing me :)

The problem is my mod supports controlling modded blocks from TGYD's BlockLoader. I bet you don't have it installed and I forgot to handle that when I was revamping my code.

I will release a new version shortly with this fixed. Meanwhile, you can just install the BlockLoader here: http://forum.spiderlinggames.co.uk/...gyd-s-blockloader-for-v0-27-spaar-s-modloader
 
#35
having issues with the new get block feature (getting errors a lot), error as seen in console and then code:

LuaScriptException: invalid arguments to method: LuaMethodWrapper.setToggleMode
NLua.Lua.ThrowExceptionFromError (Int32 oldTop)
NLua.Lua.DoFile (System.String fileName)
LenchScripterMod.Scripter.LoadLuaScript ()
UnityEngine.Debug:LogException(Exception)
LenchScripterMod.Scripter:LoadLuaScript()
LenchScripterMod.Scripter:Update()



Code:
left_wheel = besiege:getBlock("WHEEL 1")
direction = 1
speed = 0
right_wheel = besiege:getBlock("WHEEL 2")
direction = 1
speed = 0

besiege:setToggleMode(left_wheel, "AUTOMATIC", true)
besiege:setToggleMode(right_wheel, "AUTOMATIC", true)

function onUpdate()
    besiege:setSliderValue(left_wheel, "SPEED", speed * direction)
    besiege:setSliderValue(right_wheel, "SPEED", speed * direction)
    speed = 0
end

function onKeyDown(key)
    if key == KeyCode.I then
        direction = direction * -1
        besiege:log(string.format("New direction: %d", direction))
    end
end

function onKeyHeld(key)
    if key == KeyCode.U then
        speed = 1
    end
end
sorry for what is probably an easy fix, i've never touched coding before this
 

Lench

Active Member
#36
getBlock function introduces a new way to do things.

You can do things the old way (i. e. using functions)
Code:
left_wheel ='WHEEL 1'
besiege:setToggleMode(left_wheel, 'AUTOMATIC', true)
or the new way (i. e. using objects and methods)
Code:
left_wheel = besiege:getBlock('WHEEL 1')
left_wheel:setToggleMode('AUTOMATIC', true)
See the difference? What you're doing is a mix of both. If you're new to programming, I suggest you stick to one you like better (prefferably the new one).
 
#37
roger that, it works now

hopefully i can figure things out for myself, i was trying to do the newer version but i think i got mixed up somehow.

thanks for the help dude, this mod is awesome
 
#38
Hello again.

[REDACTED]
And on an unrelated note, I was wondering if you could make it so that spinning blocks could be controlled like servos. So I could set it to a specific position without having to turn and stop it manually.

[ALSO REDACTED]
Edit2: Also, it is it possible to get computer's time, like getTime() but instead of the stopwatch it'd give out the irl time?
 

Lench

Active Member
#39
Code:
hinge:SetAngle(60)
This should definitely work. However, it won't go over the block's angle limits. On the other hand, besiege:SetAngle("STEERING HINGE 25", 60) doesn't exist.

If you want to control spinning blocks like that, you will need to write your own controller. But you can use steering blocks instead which work the same as hinges.

Why doesn't the lua command work? You should be able to set variables by typing `lua x = 3`, but only while the script is running. Alternatively, you can also add global variables to Lua watchlist, then click on their name and edit them.

I'm not sure what mean by computer time. getTime() returns time since the start of simulation independent of the game. getScaledTime() returns game time, consistent with the time-scale slider. Maybe you want this: https://www.lua.org/pil/22.1.html
 
#40
Yes they're working now, I was running an older version of the mod (0.9.1) that didn't have those features yet :--DD My bad.

And oh, didn't realize steering blocks are exactly like spinning blocks, but you can control them in-game

With computer time I meant that when the method is called, it'll check the computer's time and return that (i.e. 23:56)
 
Top