Skip to content

Instantly share code, notes, and snippets.

@blam23
blam23 / GenericClass.cs
Created February 26, 2023 18:35
Generic Class Factory
using System.Reflection;
namespace GenericInitialiserTest
{
public static class GenericClassFactory
{
public static readonly Dictionary<Type, Type> Classes = new();
public static void RegisterAllGenerics(Assembly assembly)
{
@blam23
blam23 / TableTop Simulator Shuffle+.lua
Created March 29, 2021 19:36
Better shuffle for TableTop Simulator for decks users spawn in
shufflePlusTag = "shuffle+"
function onObjectSpawn(obj)
if (obj.type == "Deck") then
obj:addContextMenuItem("Shuffle+", function(player_color)
if (obj:hasTag(shufflePlusTag)) then
return
end
obj:addTag(shufflePlusTag)
newDecks = obj:split(4)
--[[
Blam's Chess Script
]]--
-- Define these completely *globally* so that other scripts can see them.
local engine_manager = {
engines = {}
}
@blam23
blam23 / BinarySearch.cs
Created November 23, 2016 20:41
"Binary" Search for a double in C#. Uses difference from needle for midpoint as opposed to halving sum
private static int BinarySearch(List<double> haystack, double needle, double tolerance = 0.0000001)
{
var left = 0;
var right = haystack.Count - 1;
while (needle <= haystack[right] && needle > haystack[left])
{
var leftDiff = needle - haystack[left];
var rangeDiff = haystack[right] - haystack[left];
var count = right - left;
@blam23
blam23 / gist:c79e0a92f37e8ad94311
Created July 12, 2014 19:13
Gifsound Auto Image Expander Script
// ==UserScript==
// @name Auto Image Expander
// @namespace Gifsound
// @description Automatically shows expanded image on page load instead of on click.
// @include http://gifsound.com/?gif=*
// @version 1
// @grant none
// ==/UserScript==
showmaxgif();
@blam23
blam23 / animations.lua
Created July 21, 2013 19:36
A little and basic animations library and example usage.
-- (c) 2013 Blam
-- Animations.lua
animation = { }
animation.__index = animation
animation.all = { }
function animation.delay(frames)
local a = animation:new{
a = 0,

Toribash Scripting Tutorial

Programming Basics Part Two

In this tutorial I am going to be going to present another simple script, and then go through step by step how it works, breaking it down and explaining it.

This time I will be explaining about Conditional Statements, Loops, Array Types and Comments.

-- Run this script in multiplayer!
people = get_bouts()

for i = 1,#people do

While

A while loop will keep going round and round until it's condition is met. Conditions are explained in the "Conditional Statements" section of the [main tutorial][tut].

Here is an example of a while loop:

x = 1
while(x < 20) do
    x = x * 2
    echo("X: " .. x)

end

@blam23
blam23 / Toribash-Tutorial-Inserts-ConditionalOperators.md
Last active December 20, 2015 00:28
Conditional Operators Segment

I took this out of the main tutorial to keep the size down, and keep this accessible.

This is part of the Toribash Scripting Tutorial.

  • > - Greater Than - If the variable on the left is greater than the variable on the right, it's true. If they are equal or the left is smaller it's false.

      10 > 20 = false
      20 > 20 = false
      30 > 20 = true
    

Toribash Scripting Tutorial

Programming Basics

So here begins your journey into how to create some simple programs. We will first start out by saying how Toribash runs the script file. If we take the example in the last tutorial:

echo("Hello!")
result = 4+4
echo("4 + 4 is " .. result)

How does the text become a program?