Etarc Coders Club

Sorry for not posting any results here yet. One little project I did, I noticed, isn’t suitable to be posted publicly, butI can describe what I learned.

In another game community, a streamer challenged us to find him on one of the public servers. His goal is to get a big spaceship and give us “a lift” on stream without the PvP players killing him or us. So I wrote a python script that scans the public server list and prints the names of players that are online, in the hope of spotting him, so I can join the challenge.

What I learned:

The library for downloading webpages is called request. I used sleep() to make pauses between requests so it doesn’t look like I’m DDoS attacking the server, I don’t want to be blocked. :innocent:

A great tool for picking words and paragraphs out of web pages is Beautifulsoup. It can step through the html in a smart way, for example, you can make it list all links, or all images in a page, or find a paragraph with certain words in it. In my case, there was a heading and some place below was the list I wanted. So I had to search for the heading, and then I used commands like parent and nextSibling to jump up and down to the list.

Write() text to a file is also a useful skill.

5 Likes

New features!

I’m using pyinstaller .\spielerfinder.py --onefile to turn the python file into an exe file. It’s huge (5MB) for such a small task, but hypothetical other users would not have to install Python to run it.

It now also prints a usage tip in the beginning and the file name of the output in the end. In case someone just double-clicks the exe, they only see the new file. The filename contains a timestamp datetime.now().strftime("%Y-%m-%d-%H-%M-%S") that only contains letters that are allowed in file names and is sortable (year-month-day).

I used argparse to let the user provide an argument string in which geographical region they are looking for players. For that I turned the server list into a dictionary where the keys are server names (“UK1”, “AU1”, etc.) and the values are the URLs of the webpages that show the player list. And if the user asks for e.g. “UK”, then I use find() to only request the URLs whose key contains “UK…”. Otherwise it lists all servers.

I don’t use index() because that considers not finding the keyword as an error, but for a filter, it’s okay to not find anything.

5 Likes

I have been a bit unwell for the last few weeks, so I haven’t been as active as I intended. I have ongoing health problems that cause trouble from time to time. I’m still working on the prophecy generator - just a simple bit of fun.

I’m still studying the base-level Python language and syntax. As such, I’m deliberately avoiding most of the add-on modules until I’m reasonably proficient in the core language. Things could easily get too confusing, otherwise.

My knowledge of Python is pretty basic at the moment, and doesn’t really justify turning my scripts into .exe files. There are other disadvantages - unknown .exe files are liable to set off every alarm you have (as, indeed, they should - anyone who runs an .exe from an unknown source is asking for trouble).

If you leave the Python code as a script, anybody with any knowledge of the language can immediately see what it does. Exe files, on the other hand, are compiled, and might as well be written in Martian for all the understanding they give.

On the other hand, I suppose releasing a compiled .exe makes it harder for people to steal your code.

Having said all the above, your project sounds really interesting, and seems to be an ideal use of Python, where absolute speed is not as important as flexibility and easy access.

5 Likes

True, creating an exe was just an exercise for myself and not a suitable format for this forum. The only usecase I have is, if my colleagues would need a script, I could show them the source code and they could confirm it is harmless.

Yeah, learn the base language first, of course. I’ve already done that (took a class offered at work plus an online class) and am now curious about all the crazy libraries that exist out there. :grin:

Hope you’re feeling better soon!

4 Likes

Much sympathy! I hope things get better for you very soon. :heart:

2 Likes

I have another idea. One of my games has a moddable (= readable) file format. It’s XML text.

I want to look into whether I could write a python script that reads all the local files and aggregates all info about all blocks in game: icon, description, properties, recipe. The second step would be a script that compares this official info with the current (fan maintained) wiki for completeness. E.g. I would like to detect outdated recipes (if I can match the block names and the page names which may differ for historical reasons).

This would also be an example where a graphical user interface would be helpful, I’ve never written one in python (only Java).

3 Likes

The standard module for this appears to be Tkinter. I confess I haven’t used it yet, as I’m concentrating on the base language, but I’ve read a lot about it.

There are a number of available add-ons that claim to help with GUIs, but Tkinter seems to have the widest support base, with lots of guidance, tutorials, and pre-built examples available. Unlike some of the others, Tkinter is also open source, non-proprietary, and free from licensing requirements.

3 Likes
1 Like

Me, a jvm programmer: Still trying to convince my boss to give me a years leave so I can go and study yourkit in the hope that I would finally be able to use it.

Python programmers: “Hoorray, we finally have a profiling tool!”

Yeah… I mean, I guess having one is important, but believe me, it solves nothing on its own… The AI interpretation of the output sounds like a great idea, but I’d have to see how well it works first. The obvious stuff you can spot yourself, and I’m not sure chatgpt will be able to give any help with the non-obvious stuff.
And it certainly won’t fix the issue of python, being an interpreted language, just being slower than compiled languages by definition. Change that, and you kind of take one of its biggest advantages away with it. I really don’t understand why the language is being used for large software projects. It’s not what it’s made for, and not what it’s good at. It’s kind of the same madness as node.js (I mean, node as a dependency managment tool is pretty great, don’t get me wrong. But writing backend code in javascript? How did anyone ever think that was a good idea??)

5 Likes

So, I’m actually doing this. I extracted most of the game data I need from the XML files, enough to generate recipe InfoBoxes for the wiki. I’m still fiddling with generating the InfoBox syntax correctly (it wants me to merge item variants in a specific way) but it looks like a solvable problem.

I also found a way to match the historical/internal and the public block names. They have IDs that I can look up in a localisation file!

I don’t think I will be able to compare the recipes automatically with the live wiki though. I’ll update the recipes in the wiki manually once, and I’ll keep the previous extracted data, and after each game patch, I’ll auto-compare the new and old extracted data, and manually update any changed recipes. That seems easier.

I was at a large fan meetup for that game and that encouraged me. :slight_smile:

4 Likes

Ah yes, I guess you are talking Templates here. Gotta love (or hate) those, not something you’d like any user to start messing about with, even though such wikis are usually relying on the general public, lol. It can get quite messy I can tell from experience.

Fandom/Gamepedia/MediaWiki
Some general info on those templates, not surprisingly very similar

Done this for several years way too actively, together with various site running scripts and whatnot. It has been fun for the time, but I don’t think I’d like to get back into this again though.

2 Likes

:100: Hah, you recognised it right away! :smile:

Someone years before me (the game’s EA/alpha was ten tears ago and the full release is still getting large updates) created all the templates already. I just have to update the numbers after a rebalance.

Recently I took random samples and found many outdated Recipe boxes from the time when the wiki had nobody maintain it… And to look up recipe details, I have to tab back and forth between the browser and the running creative mode game and place each block… Now that I can read them from the game files, that saves me one step. If I can convert that table (CSV) into the wiki template format, that’d speed up the process to a simple copy & paste.

2 Likes

For the interested coders-to-be among us: reading the moddable game files was actually fun. There were lots of folders and I opened random files in NotePad++ to see whether I could spot anything familiar. A folder named GUI contained icons (that I could open and convert in Paint.Net), something with “localisation” contained familiar block names but no info, and a folder named “Cubes” contained recipes and sizes. Etc.

Nothing in the game UI is called “Cubes”, by the way. So I learned that the terminology we players see is different from what the game files call things. Some machines and weapons had plain names like “largecalibre”, “smallcalibre”, “arcfurnace”, but nothing in the game is called that, players see them as “large assault cannon” or whatever. The “Cube” information had a name id and the localisation file had the same ids, that’s how I learned I had to add a function to look up the real names for my table. (Also the default English localisation file had no ISO language code, how inconsistent! :stuck_out_tongue:)

Now I’m looping over my table, each row is one block with its recipe, but some blocks come in pairs, and the wiki template wants me to put both recipes together, so I’m having fun updating python dictionaries. If you reuse variables in a loop, remember to copy() the content, or else your dictionary will just repeat the same line…

Recipes in the game files have a certain format, if ingredients are repeated with a different value, the second value is an optional ingredient that just adds more hitpoints. In my first script version, I didn’t expect that and just overwrote the mandatory value with the optional one…!! I fixed that by tracking the second values in new columns and mentioned that to a friend who is an experienced developer. He said, what if that line is repeated a third or fourth time? My first thought was, well that cannot happen, it’s either optional or mandatory, right… ? Of course I found several cases where optional ingredients could repeat more times… (in game the block looks like a shelf that stores those extra ingredients). So now I need to handle that case too! Always check before making assumptions…

I’m still looking for mass and wattage info. Remind me to use NotePad++ to run a full text search on the word “mass” across all files while I go to the market. :sweat_smile:

2 Likes

I remembered this old thread and thought it might be a good place to ask :slight_smile:

I am working on my Lore Compendium, going through the Lang_Files and putting it all together in Google Docs because it’s handy.

I’ve managed to write a script for doing a search for a word and applying a colour (for handy colour coding to match the game’s identifiers)

What I’m trying to do now is create a script for google doc that Removes all text between two points.

Basically a lot of the strings I’m deleting, begin with </ translation> and end in < translation>

This is because I’m keeping the text between and </ translation> in most cases.

I don’t want it to get confused and delete stuff between these two identifiers, rather everything else outside of it.

Basically my script needs to say “begin deleting after </ translation > but stop as soon as you hit < trans lation> then start again after </ translation >”

Prefereably I’d want it to do a line break after clearing everythign too.

I’m sure theres a very simple line of code that does this and I’m over complicating it in my head but if anyone has any experience running Scripts in Google Doc I’d appreciate the help :slight_smile:

I just did it all MANUALLY for all of the Autophage Content. Dialogue, missions, story, monoliths, items etc ':slight_smile: And I’ve decided before I tackle the rest of the Lore… I could do with a script for the niggle work

2 Likes

You can use XSLT to pull out the translations using something like XPath Tester in VSCode or SketchPath. I use SketchPath more, but takes getting use to. I can’t find a working download link for it unfortunatly.

The xpath query:

//translation

will pull all the translation elements out of the xml document.

2 Likes

Oh cool thanks, I’ll give it a shot :slight_smile:

I got VScode and trying to use XPath Tester but no idea what to do.

There is two input boxes for Xpath, “Xpath Expression” and “Context Node”.

Typing //translation in to Xpath Expression gets it to highlight them in the open Xml (Just the < translation > and < / translation> part, I don’t know if its highlighting the text in between) but I’m not sure how to extract this information, or what should be put in context node etc.

Thanks again for the advice so far <3

1 Like

Sounds like a job for Regex, your grumpy neighborhood write-only parsing language…

3 Likes

I should make it very clear I know nothing about coding and have never used any coding software. And I’m hitting the same brick wall everywhere.

I tried a browser version of RegEx, entered a string to highlight the text but I do not know how to extract it…

I then got a regex extension for Visual Studio Code that says it has easy extraction shortcuts for string highlights but, I have no idea how to run this regex extension in VCS on the XML. It’s asking about Json and picking fiolders and config files and the reason I failed math and can’t read music or learn a language comes to the forefront and my brain feels hot '^ _ ^

What am I missing? Is there an easy “here this regex just works” ?

I feel like doing this manually will just be quicker for me cos I’ve been trying to figure out how to run code for 4 hours now '^_ ^

2 Likes

I personally use NP++ regex to get this done and only be left with the ‘ID’ and ‘value’.
You could of course try to write a script within Google (extension), but it uses Google Apps Script, which is not great to be honest.

For a simple NP++ regex, I currently use the following on only the English Localisation files:

Find:

^\s{6}<Property name="Id" value="(.*)" />\r\n^\s{6}<Property name="English" value="(.*)" />

Replace

\1\t\2

Note: You have to search using Find/Replace, check the box for regex, do not check the period to be used for matching ‘newline’. Of course this also depends on the format you got for the decompiled EXML files. I can explain the regex, and adjust it as needed if you wish.

You will have to manually clean up at the start and end, but that is easy.
The result is a ‘tab separated’ list of IDs and values (text), so it is an easy copy paste into Google sheet. If you wish I can provide sheets for you whenever I update them myself, which also combines the separate files into a single sheet to have it all together. I’ll provide you a link to a copy of my latest (5.10) in DM

3 Likes

Thanks @DevilinPixy :smiley: Will check the DM now. It will be useful to learn how to parse out info using code so will try out the suggestion using NP++

Edge is my default .xml viewer for some reason, recent Win update must have done something, I thought I was typing into my chrome browser and was surprised that I had a search result with co-pilot telling me the exact string of code to use in various different programs '^ _ ^

I knew google was dying but I didn’t realise Bing was no longer a meme.

2 Likes