Results 1 to 14 of 14

Thread: The Lua API. (Oh God.)

  1. #1

    Lightbulb The Lua API. (Oh God.)

    So. The Lua API. MoonSharp. Yeaa.
    I've had quite a bit of my own fun with the API doing a bunch of stuff. Unfortunately, I've had just as many frustrations.
    I feel that the Lua API is very limited in scope and not many things have been touched on. It honestly feels like not much thought has been put into it.

    I've made a list of suggestions for the API that are in no way comprehensive or very great in quality, as i did write this taking things off the top of my head and looking at my existing scripts.
    If i make changes to this, i will change the post's title/desc accordingly to make the changes easy to notice.

    Suggestions and changes to the list are welcome. I'm aware that making the API itself is not as easy as "oh hey put this here and here" in some cases. These are simply suggestions.

    Code:
    --[[
    	Suggestions:
    	Events: 
    	- (Please) give us events that can be stopped. 
    		> Either entirely new events or a modification to the existing ones that lets us stop it from running.
    		> An example is onPlayerChangeColor. I want to be able to stop the player from changing their color if something == something.
    		> So i can return false and the player will simply not change color. Having this for a lot of events would be (very) useful.
    	
    	Event Suggestions: - Suggestions for things that could use an event/hook.
    
    	- When the player has clicked/right clicked somewhere/on something using the grab tool(even if something isn't grabbed)
    		Ex: onClick(color, position)
    
    	- When a player is:
    		- Muted/unmuted
    		- Banned/kicked
    		- Flipping the table
    		- Changing their current tool
    	- When an object is locked/unlocked
    
    	- Pinging
    		Ex: onPing(color/player, position)
    	- Flicking an object
    	- Creating text on the board
    		Ex: onTextCreated(color/player, position, text, fontsize, textcolor)
    	- Placing a decal
    	- Creating a joint
    
    	- When the notebook has been changed
    	- When the notes have been changed
    
            - onObjectRandomize: This event doesn't run when the player tries to shuffle/randomize while the object is being held? I'm not sure how this is handled by the game but i'm making it known.
    ---------------------------------
    	Functions: -- Suggestions for new functions to add. Some of these may be in the wrong section or a bit un-organized
    ---------------------------------
    		Player:
    		- Set turn/Pass turn
    		- Getting the position of a player's hand zone
    		- Setting their current tool. (including ones they wouldn't have access to?)
    			Ex: ply:setTool(tool)
    			"tool" could be a tools name(str) or an index.
    			ply:setTool("Joint")
    			ply:setTool(7)
    		- Getting a player's object with their steamid
    			Ex: getPlayerBySteamID("765.............")
    		- A function for prompting the player if they want to open a specified link.
    			Ex: ply:openLink(linkurl(str))
    			> Didn't think about suggesting this at first because of how it could be abused, but then i realized it can already be abused.
    			> You can already be annoying and abusive with link opening, and the choice is left to the player either way.
    	
    		Object:
    		- putObject: The putObject function will currently not allow you to put a stack of chips into a bag. Only singles.
    		(This is of course, the same even without scripts.). Fix pls?
    		- A function for setting the quantity of a bag/chip pile and/or adding objects directly to them. 
    			Ex: Say i have a pile of gold with 8 chips in it. I could run goldpile:setQuantity(goldpile:getQuantity() + 1) to increase it by 1.
    		- Flick an object?
    		- Get all objects touching the current object.
    			Ex: obj:getTouchingObjects() 
    			> This would return a tbl of objects that are currently touching or have a connection between the object.
    
    	
    	
    		Misc:
    		- A func for converting RGB to Hex?
    	
    		Global:
    		- A func for getting the name of the board.
    		- Another func for getting the name of the game itself(the title the player set)
    		-- Functions for doing things the player can do but scripts currently can't
    		---------
    		- Placing text at a specified position
    			Ex: placeText(text, font????, <font_size>, <color tbl>) --everything after text an optional argument
    		- Placing Points (Snap Points) at position
    		- Placing scripting zones (and other zones) with border vectors as args
    			Ex: placeScriptingZone(position1, position2)
    			Ex2: placeHandZone(position1, position2, color)
    		- Placing paint(s) at a specified position?
    			Ex: paint(position, color, size)
    		- Making joints between objects
    		- Placing decals (and a way to loop through available decals for the board)
    
    		- A function for creating a line like the line toolat specified positions with color/delay arg
    			Ex: lineFunc(position1, position2, color, delay)
    			@param position1/2: The 2 points the line will be in between
    			@param color: the color of the line (default white?)
    			@param delay: how long this line will stay here(default var?)
    		----------
    	
    		Func Changes:
    		- printToAll: Make it so the color table will have a fallback value(white?) to use and it won't error out when you don't enter one.
    		- broadcastToAll: same as above
    
    		- clearPixelPaint: Either a new function or an argument to clear the paint of a specific player rather than the whole table.
    		- clearVectorPaint: Same as above
    
    	----------------------------------
    	Functions End
    	----------------------------------
    
    	Key Bindings:
    	- An optional keybinding for copying the GUID of an object & the lua editor? Please?
    
    	-----------------
    	My biggest complaint(s) (yes this has it's own section)
    	-----------------
    	My biggest complaint(deja vu?) is "cannot access field" errors. I want to be able to store variables and create functions for the player class,
    	but instead i constantly find myself making small workarounds to do stuff like this instead.
    
    	EDIT: So as stump has pointed out, communication between objects is possible. I feel like i was going to put something else here, but i'll
    	leave it.
    
        I can't create new meta functions for the player, nor i can i modify existing functions and detour them.
    
    	It's stuff like this that makes things so irritating to do. I have to work around things that shouldn't need to worked around.
    	In fact, i've been thinking of using the notebook pages as variable/table storage between objects because of this issue (apparently not!)
    
    	Another issue i have with this is the fact that all of my code is crammed into one object.
    	For example, i've made a hook system for the events so that i don't have to cram stuff into one event func.
    	If i want to make some hooks like this on another object, i have to copy the whole hook system over.
    
    	The script i'm currently working on is crammed into one object, 800 lines long, ~30k characters. Can't even be viewed in-game.
    
    	-----------------
    	My biggest complaint(s) End!
    	-----------------
    
    ]]--
    Last edited by Zekiar; 09-15-2017 at 01:56 PM.

  2. #2
    Join Date
    May 2016
    Posts
    1,072
    Hey, I gave this a read over. I have some general comments, but it is nice feedback.

    You may be able to place text using the text tool, as part of spawnObject? I'm not sure, I think I remember hearing somebody say they did it, but I don't have a reference saved and its lot listed in the spawnObject KB page.

    "cannot access field" errors may be a result of the "sandboxing" environment we have to work in. Letting you modify the player class could make some things nicer for you, but it might also be abusable. But I'm just posing the possibility, I don't know one way or the other.

    Object scripts ARE able to communicate. In your example you have a manager would use object1.call("cleanup"), object2.call("cleanup"). Details on it are in the object page of the Knowledge Base (KB)

    You can also use setVar/setTable but you may be right about not being able to set a variable to a class directly. You might have to use a helper function to use call on, passing the variable information as the "parameters" argument

    DO NOT TRY TO USE THE NOTEBOOK AS DATA STORAGE, the notebook is buggy and unreliable. It will seem like its working then you will be tracking down some bug only to find out you can't read a notebook tab thats right in front of you or it is returning a notebook tab that was cleared/deleted incorrectly. Just don't haha. You CAN use Global.setVar for storage, or if this is for a specific item, you can write it to the objects save_state data (I can tell you more on this if you're interested).

  3. #3
    Quote Originally Posted by MrStump View Post
    Hey, I gave this a read over. I have some general comments, but it is nice feedback -snip-
    Thanks Stump, i'll adjust the post accordingly. I'm very aware of the sandboxing environment and that's one of the issues i had with the API. I feel like it's *too* restrictive, but that's just my opinion. Whether it's changed or not, i'll still make new suggestions for functions/events to add.

    And while creating a text object may be possible, i feel like it shouldn't be necessary to do that. I noticed a lot of the things players could do, scripts didn't really have much access to.

    Also, thanks for the info about objects! It's not ideal at all, but it can work. My previous complaint still stands though.

    In addition, a lot of talk can go into abuse, but at the same time it can be argued that things can already be easily abused. Scripts can *always* be abused, and always will be in a multiplayer game, whether you sandbox it or not. In the end, it's the player's choice whether to use a specific script or not. Whatever happens will stay in that specific game, after all. Even if you try to open 1000 links on a player or mess up their player class somehow, once they leave the game it doesn't really matter. So the talk about abuse is kind of redundant.

    I feel like the API has a lot of potential in a game like this, and I'd hate to see it restricted because of minor concerns over how much it can be abused that have been repeated in literally every game with a scripting API.
    Last edited by Zekiar; 09-13-2017 at 09:45 PM.

  4. #4
    Join Date
    Apr 2016
    Posts
    175
    Quote Originally Posted by Zekiar View Post
    So the talk about abuse is kind of redundant.
    Abuse is not redundant. I had hacker spawn a custom object that injected its code onto another random object that simply keep respawning. If you give more power to the scripting engine there will always be someone to abuse it.

    Quote Originally Posted by Zekiar View Post
    once they leave the game it doesn't really matter.
    Not if it crashes your TTS, which is possible.

    I would love more functions, but I also see the need to be careful with just allowing everything.

    Flolania

  5. #5
    @Flolania
    You can't detect "malicious" scripts, there's no definition for that. Only promoted players can spawn stuff in and we're just not supposed to promote random people because they can screw the game up. They don't even need to know scripting - select all, copy, hit paste 50 times and the host crashes. Restricting scripting from some functionalities because it's potentially harmful doesn't make much sense as long as we maintain the situation where only host and promoted players can affect the system at all.

    @Zekiar
    I'm also sad there's no way to directly share/pass functions between objects. If you use Atom editor you can use #include command which will shave off some lines (visually) when editing to keep your sanity. It's much more efficient to include e.g. vector operations in each script than try to cross-call it (and oh god it takes hacks to make that work with reasonable syntax).

  6. #6
    Moved to Scripting Suggestions

  7. #7
    Thanks, seven! I didn't even know this was a thing for some reason

    Quote Originally Posted by dzikakulka View Post
    @Zekiar
    I'm also sad there's no way to directly share/pass functions between objects. If you use Atom editor you can use #include command which will shave off some lines (visually) when editing to keep your sanity. It's much more efficient to include e.g. vector operations in each script than try to cross-call it (and oh god it takes hacks to make that work with reasonable syntax).
    Unfortunately, I've always had issue after issue with Atom in the past despite how much i like it, and I'm also very used to sublime, so this isn't a choice for me. I def need some type of way to make it so a certain function/table can be accessed by everything on the board, or I'm gonna go crazy at some point.

    Quote Originally Posted by Flolania View Post
    Abuse is not redundant. I had hacker spawn a custom object that injected its code onto another random object that simply keep respawning. If you give more power to the scripting engine there will always be someone to abuse it.



    Not if it crashes your TTS, which is possible.

    I would love more functions, but I also see the need to be careful with just allowing everything.

    Flolania
    You may have misunderstood what i meant when i said talking about abuse is kind of redundant. In every game, with basically every scripting API, and of course even without them, there will always be people that will abuse scripts and everything else just to simply be dicks(is swearing against the rules on forums?). This can be seen commonly in TTS servers, where random people will blow in the door just to lock your whole table, throw things around and generally just be downright annoying. When it comes to crashing and lagging other people's games, i come back to the same argument. The exact same thing can be done by a normal player with promoted permissions. After all, they wouldn't be able to do much substantial without those permissions to begin with. So, it is the HOST decision whether they want these scripts/players to have that. It is also their choice to use a specific object/board, especially if after they have experienced it *try* to be malicious. They simply won't use it. A normal player with admin permissions can still easily crash & lag your game, or kill the host connection just with the available in-game tools. This is an accepted part of the game. If it wasn't, we'd be removing basically every tool and fun functionality to cater to the people who think everything needs to be restricted because it can be abused. And a malicious script in this game would be hard to call malicious to begin with. The uncreative script kiddies would, and still can right now with the available functionality in the API, just create annoying crash & lag scripts, which in the end would still not affect anything beyond the game. This will happen in EVERY situation. In fact, the only reason it doesn't happen often now is because the scripting API for the game is not well known, and the game's community is low on actual "coders" anyway.

    My point is that you're speaking about trying to restrict things for the game's future which can ALREADY easily happen. Your argument is only harmful for the development of something like this. In a proper environment, scripts cannot be abused to cause any real harm to a user beyond their game. I am in no way saying that anything and everything should be allowed. That just leaves it wide open for exploits and annoyances everywhere, and for a game like this stuff like that really isn't needed. We don't need a toxic, uncaring, elitist scripting community with the usual skids that will just crash people's games for "funzies". However, at the same time the game's API development should not be over-hindered by trivial back-and-forth argument about how the functionality of the API can be "abused", like literally everything else can be abused.

    Also, your concept of a hacker is very misinformed. What you have described is simply an annoying scripter which has created a (very simple, mind you) script that will respawn a certain object. There is no fancy words like "injecting codens". There is in fact an object function that will allow you to change the script of a specified object. So... Do you want to remove that just functionality because of one group of people?

  8. #8
    Join Date
    Apr 2016
    Posts
    175
    Quote Originally Posted by dzikakulka View Post
    You can't detect "malicious" scripts, there's no definition for that.
    Huh? I don't think I said anything related to this, but you can "detect" them when your game crashes after you join.

    ... and I was correct about abuse. Just because copy and pasting is one way to crash TTS, it isn't the only way a script can screw with users. Idiots could host tables and still run scripts on people that join random games (TTS does so well). I don't want to go into details, but people can abuse scripting; which is all my comment was about.

    Quote Originally Posted by Zekiar View Post
    Also, your concept of a hacker is very misinformed. There is no fancy words like "injecting codens". There is in fact an object function that will allow you to change the script of a specified object. So... Do you want to remove that just functionality because of one group of people?
    Just so you know, inject means to introduce into something which what happened. Just because I used a term you were unaware with, doesn't mean my example wasn't valid. I know what a hacker is and the difference between script kiddies. I think you should reread my post above and take note of my last statement: "I would love more functions, but I also see the need to be careful with just allowing everything."

    Flolania

  9. #9
    I'm much more worried about promoted players being able to cheat than about them being able to crash the server. If they crash the server then you just reload and continue.

  10. #10
    Quote Originally Posted by onelivesleft View Post
    I'm much more worried about promoted players being able to cheat than about them being able to crash the server. If they crash the server then you just reload and continue.
    This will happen no matter what. You shouldn't be promoting people you don't trust. That's the whole point of being promoted in the first place. If you just trusted everyone with everything(which the game did before lol), everything comes unhinged. In addition to this, any decent script would likely notify the host of anything notable your promoted players are doing. It's already possible to cheat as promoted(and host).

  11. #11
    Yeah, sorry, I should have added "and I'm not very worried about that", because; what you said.

  12. #12
    Hey there. I gave a quick read. I see that some features have been implemented (position of player hand for example). Are there any updates to Pass Turn???

    I've been searching and searching and it puzzles me why this is not available to Modders. I don't understand why the developer would choose to not make turn passing available via LUA scripts. Was this done intentionally or just overlooked?

    I find that interaction with the turns feature critical for a successfully game setup--the work arounds are bandaids. I mean you have Workshop mods that completely bypass the turn system with their own custom code, because it's the only way anyone has figured out how to make any turn based script interaction work correctly in LUA.

    The turn system should be LUA interactive, not require custom LUA scripts and content to bypass a built in game feature.

    Could a developer inform the community how this can be achieved?

    Could anyone explain how to pass current turn with in a script.

    I've been scouring the API and talking to fellow scripters on Discord and nobody seems to know how to pass a turn in a script.

    I imagine it should be a global function you call that passes the current turn to the next player in turn order. However, I cannot find any reference to it. It's obviously in the game with the Pass Turn button in the UI (top center screen). I cannot think why the developers would not give Modders access to this function.

    Also, setting:
    Turns.turn_color = "Green"
    does not set turn to Green

    Thanks!
    https://steamcommunity.com/app/28616...2523069503679/
    http://www.berserk-games.com/forums/...ight=pass+turn

  13. #13
    It is far from ideal, but you are able to interact with turns through scripts by reloading it like this

    Code:
    function setTurnOrder(order)
        Turns.type = 2 -- Enable custom turn ordering
        Turns.order = order
    
        -- Yes, really..
        Turns.enable = false
        Turns.enable = true
    end

  14. #14
    So if the turn is set to White before the script is executed, and you execute the script and it sets the first player in the Order to Red. Will this script change the current active player in turns to Red? I've tried this script, or something very close to it and could not get Red activated as current turn.

    Quote Originally Posted by MoreThanTom View Post
    It is far from ideal, but you are able to interact with turns through scripts by reloading it like this

    Code:
    function setTurnOrder(order)
        Turns.type = 2 -- Enable custom turn ordering
        Turns.order = order
    
        -- Yes, really..
        Turns.enable = false
        Turns.enable = true
    end

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •