Writing a Wiki Bot

As part of the wiki re-fuckulation process a month back I had to move and reformat a bunch of pages. So I went about writing a wiki bot.

If you already have good knowledge of PHP this is about a billion times easier than it sounds due to a useful little library called wikimate. Its github page speaks for itself, it’s incredibly painless to read page text, set page text, delete pages etc.

So as an example.. one of the fucked up things about the old wiki is that it didn’t use categories. All of the functions were painstakingly listed on a page. So if you removed or added a function you had to edit this index page too. That’s not how a wiki is meant to be indexed. So I went about getting all the listings on those pages and converting them to a new template, so they would be categorised properly and also be editable via a form.

When I’m posting this code I’m now showing you great coding – I’m showing you code that got shit done.

image

So this function looks on the Libraries page and splits it by newlines – so that $lines is an array of lines. Then if a line contains “{{Lib” it trims shit off, splits it by | and calls ConvertLib.

image

ConvertLib does pretty much the same thing. It gets the library’s index page, goes line by line looking for LibraryFunc. Then it splits by | and calls Process.

image

Process is kind of a big boring function, so I’m splitting it into sections here. This part gets the target page. If it already exists then we already did our work, so it bails. If not it get the source page. This is the page we’re gonna be reading and converting to the target page.

image

It reads the page contents into $text

image

Then it tries to find the information we need for the new page. This looks more complicated than it is. It’s basically trying to find text between two other pieces of text. There’s a bit of fucking about to get this to work properly.. This is probably where regex works well – but who wants to learn how to use regex – right?

image

Once we have the info we can build $out – in the format that we want.

image

The arguments were stored in a really shitty way under a single template (Arg1Name, Arg2Name, Arg1Type, Arg2Type blah blah). In the new system we store the arguments unnumbered under the Arg template – and fuck about adding numbers in javascript after the page is rendered.

image

The final thing is to set the text of the new page, and delete the old one. We set the delete reason on the old page so future generations can figure out why we did what we did.

image

How was I running this? Well you just install PHP and then you can open a command line and run “php.exe convert_libraries.php”. You don’t need to go through the trouble of uploading to a host and running it in the browser.

I had lots of fun playing with this stuff and I think it has made the wiki much friendlier to edit! So everyone wins!

Oil your brain

In my house I am renowned for obscenely long showers. I can sometimes be in the shower for an hour and half. That’s not always because I’m having a difficult shit, or playing candy crush, or masturbating. The shower is where I oil my brain.

I saw something on TV. They did a test. They got 3 subjects and gave them a creativity test. They had to come up with as many uses for a brick as possible. Then they stopped them. One was told to sit and do nothing for two minutes, one was told to do a demanding task for two minutes, and one was told to do a brainless task for two minutes. Then they did the test again.

They found that the guy who sat doing nothing couldn’t really come up with any more uses for the brick – despite having lots of time to think about it. The guy doing the demanding task didn’t do too well either. But the guy who did the menial task came up with a shitload more uses.

This confirmed something I’ve thought about for a long time. When I get out of bed I code for a bit and read all my emails. I fill my brain with problems. Then I have a shower and my brain works out all the problems. I find myself planning stuff really clearly. My brain is still working, but it’s not using it’s full capacity. So when I get to work it’s all ready to go.

There’s lots of these ‘working shit out’ activities you can do throughout the day. Here’s some that I do.

  • Wash the dishes
  • Mow the lawn
  • Do some DIY
  • Wash your car
  • Vacuum
  • Make a coffee

Keep your brain well oiled.

Tax Investigation

Yesterday we had a woman from the tax office here having a nose around.

Facepunch doesn’t really pay a lot of VAT because we don’t sell GMod straight to the end user – we get a royalties cheque from Valve every month. The only VAT we charge is on the forum upgrade system.. so when people buy titles or upgrade to gold membership etc.

So every we always get a VAT refund from them for all the shit we buy, our accountancy/legal fees and our rent. So it’s routine for them to check into people like us – because they’d kind of be idiots if they didn’t.

But there’s a problem. No-one can agree what the rules are for these forum upgrades. Should we be charging VAT at all? Should we be charging VAT to people only in the EU? Should we be charging it to everyone in the world? Even the tax woman didn’t really know, and kept flip flopping between different answers. Our accountants have told us to charge people in the EU – so that’s what we’ve been doing.

It seems kind of crazy that something that should be so simple would have so many different rules, that are so ambiguous that you can bend them whatever way you want. If the people running it don’t know the rules – what chance does anyone else stand?

Lua Bindings

I’ve been updating how my Lua binding system works over the last few days. My original system was getting me in the shit with co-routines because I short sightedly stored a global Lua instance and accessed it from everything.

While this has worked, and is accessible, it does fuck me about in a lot of ways. Like I can only really have one Lua instance in each dll realm (menu, client, server). I’ve got no need to have more right now – but that’s not the point.

My old bindings looked like this..

ss (2013-03-13 at 04.37.28)

The calls to Get_Entity  and Get_Float are what are bumming me. They’re accessing globals.

So now my bindings are looking like this.

ss (2013-03-13 at 04.36.24)

The ‘lua’ variable is passed to the function from a function that the LC_Function macro creates. It’s no longer retrieved from a global – it’s retrieved from the lua_state that is passed by Lua to all function calls.

I also started documenting the functions in a way that I can parse with a PHP script, turn to JSON and automatically throw at the wiki. Something I really really wish I had done over the years for the 2,000 other functions.

Office Progress

The mailbag post I made a few days ago got a lot of attention. Lots of speculation about my game idea. I get why, but I fucking hate it. Nothing we ever make will live up to the success of GMod. I don’t want to be a AAA studio making massive budget AAA games. I want us to make small indie games. I want to be like introversion – not gearbox. So when people hype themselves up it’s only setting everyone up for a fall.

So anyway. We’re still in the process of renovating the office and hiring a team. We’ve pretty much hired two really promising artists so far – hopefully to be starting in April.. and our new receptionist started today. I’m struggling to find programmers though. It seems good programmers are few and far between.

We advertised on monster for a UI/graphic artist and a programmer. There have been about 10 times more applicants for the artist position than the programmer position. A lot of people applying for the programmer job have very little actual experience. One guy applied with no computer experience at all.. his only work experience was running a pub. He listed one of his hobbies as reading the holy bible.

Maybe monster is the wrong place to be hiring programmers. Where should I be advertising? Do you know anyone that’s looking?

We’ve been concentrating on getting our reception area and meeting room finished over the last couple of weeks. Here’s some photos!

2013-03-02 09.42.09

2013-03-10 10.53.33

2013-03-10 10.53.51

Paths

So, part of the NextBot stuff is the idea of Paths. They’re pretty cool. You give it a target position and it will try to create a path to that place. Not just a simple path – but they can include jumping over gaps, and climbing up ladders.

They’re stupidly easy to use too. I’m trying to code them in a way so that they can be used independently of NextBot stuff, but this is the general idea.

ss-2013-03-11-at-04-40-55

So, in this code every second it’s re-computing a path to Entity #1. This is obviously just a test.. in single player Entity #1 is the player.

Here’s the result..

As you can see, they follow the player pretty religiously.. although they do seem to get stuck on each other when they’re colliding. I’m not sure whether that’s something I should handle in-engine.. or just expect the Lua coder to detect and protect against the AI getting stuck.

Next Bot

I laid the groundwork for the nextbot bindings today. The NextBot stuff is what the AI in TF2 and L4D use. It’s kinda the reason I have slacked binding any decent AI stuff up.. because I think this system will replace all the old AI stuff.. just because it’s much much simpler, cleaner and more powerful than the old stuff.

I’ve only exposed 3 functions so far, and I’m already loving playing with it. The video above was created with this little bit of code below.

ss (2013-03-07 at 03.38.09)

There’s a lot of cool stuff to be exposed so the hope is that soon it will be a simple task to make NPCs and Bot AI in GMod!

VPK Search Paths

Today I fixed the VPK search paths issue.

The issue was that when you were opening folders to show the game content in the spawnmenu.. previously all VPK content showed in each folder. That was obviously wrong.

This was happening because the VPK stuff internally has no sense of search paths. They get searched all the time no matter what search path we’re specifying.

So we add this code to the VPK class..

ss (2013-03-05 at 02.07.06)

Then we can set what search path it’s meant to be on. In GMod we set up a new search path for each mounted content ( called “tf”, “dods”, “portal2” etc) so we can search only that mounted content. But the path is also added to “GAME” so that the content will actually get loaded. The code above isn’t really flexible but it serves our purposes.

The anywhere that VPK files are actually accessed we do a quick check using the provided PathID.

ss (2013-03-05 at 02.11.12)

And now we have searchable VPKs working properly!

Portal 2 content is back and all working. Although there are some crashes due to them all being a newer model format and me having hacked the shit out of stuff to get them working in the first place.. but I’ve fixed a couple of crashes so hopefully 99% of them will work without crashing.

cp_degrootkeep0001

cp_degrootkeep0003

arena_offblast_final0000

cp_degrootkeep0002

Mailbag

What direction do you ultimately want Dust to go in? Gah, RUST. I mean’t Rust.

We really don’t know. We have a bunch of ideas we want to try. Zombies are done – we are sick of zombies.. so we wanna get rid of those and add other NPCs. We also want to add building elements and stuff. Really – it’s just an experiment, and we’re gonna see where it leads.

What brought you into programming? What was your first computer? What was your first ‘application’ you ever created?

I think I’d played all the games on our Sinclair Spectrum, so started reading the manual and exploring the menu. I’m curious by nature – so if there’s a menu option I’m gonna have to look at what it does. My first application that I can think of was called quick flicks or something. It flashed the screen and a circle slowly drew itself over the screen. I didn’t know what I was doing really, but I managed to save it to a tape so I could load it at any time. I was about 10 I think.

2558449265_db27bdc740_z

Do u ever get noticed jn public or have crazy ass fans.

Nope! Never been recognised in public. I have had weird stuff left at my front door – like flowers and stuff. But nothing really really insanely crazy since the Andy stuff in 2009.

do you look at your poop after you’re done pooping?

No, I’m pretty lazy, I wipe and flush without getting off the toilet.

What’s next for Garry’s mod?

Hopefully we’re gonna get the Linux version out. Then hopefully we’ll move to SteamPipe, and I’ll get the NextBot stuff hooked up.. then I want to do another Gamemode Contest. But I want to knock out a bunch of gamemode creating tutorials first to help people get their foot in the door.

How much money have u made from gmod if u dnt wanna be specific r u atleast a millionaire

Over 7 years GMod has made about 22 million dollars. We get less than half of that though. Then the tax man gets a bunch of that. Then when we take money out of the company the tax man gets a bunch of that too.

Besides Rust and Garry’s Mod, what is Facepunch Studios LTD working on?

We are starting work on a new PC game. It’s a game I’ve wanted to start work on for ages. I’m trying to get a team together in office to build it this time.. I don’t really want to talk about it until we’ve got something more solid though.

Can you see a future for apple in the mobile space, or will the iphone go out of fashion some day?

I think Apple would really have to fuck up to lose their position right now.

Wat does ur family think of gmod

They know of it – and they tell me when they’re browsing youtube and they see Gmod on there.. but I don’t think they’ve ever played it.

Will you make playable TF2 character skins? I would love to see them :D

It’s something I’ve talked about with max – but he reckons it’s pretty much impossible

Do you see linux support for gmod happening in the short term or the long term? Or not at all?

Yeah it’s definitely gonna happen. I’m just waiting on Awesomium to release their Linux version so I can ship!

does ur girlfriend understand garrys mod and what it is?

I think so. She hates how much time I spend on it though. She’s a yoko.

blocco is a shit hole agreeed?

I don’t think the place itself is a shit hole. There’s a lot of people that seem like they’ve given up all hope.

Will export to hammer ever come back? If not, Why?

I did add Lua bindings that let people do this – but no-one has. I’ll make an addon for it one day.

How many steam friend invitations do you receive on a daily basis?

I’d say about 10.

Do you like your community at Facepunch?

Which one? There’s like 20 different sub communities.

The question I have is are you still planning to implement native shader support into garrysmod, the most recent talk of this that I can remember was between you and Tobba in his thread.

Tobba’s shader system worked but it wasn’t really possible to do anything complicated with it as far as I could see.