The Android Invasion (Part Two)

Some details

Code: A Summary

I’m not going to publish my whole Code here, but I will present a short explanation of how my App is structured.

Main Files:

  • activity_main.xml – this displays a set of labelled Buttons, one for each Category of List.
  • Main Activity – this contains the control-code for the Buttons, chooses which Activity to launch, and what message to send to it.
  • Several Activities, for different types of List.
  • Several Adaptor (or “Helper”) files, for processing the Lists, and binding them to the Recycler view.
  • A “Class” file for each Category. These define an Object-Type, and show how each Object holds Data*.
  • activity_(category).xml files, with data about how to display each List type
  • (category)_list_row.xml files for showing how each Row of the List should display.

Why Multiple Category Files?

As this was my first real foray into Android Coding, I chose to split the Categories into two main types. Type The First were ones that could be express as “Names”. i.e. two pieces of Data. (Forename and Surname). This applied to Treasures (Type and Amount/Quality), Items (Alchemical, Mundane, Furniture all have Type and Material). Type The Second were ones that did not fit this structure, and each got it’s own set of Files/Classes/Activities/Helpers (Adaptors). e.g. Quests and Locations.

I could have piled up a single set of files with “IF <quest> then <do something different> else IF <Location> do <location code>”, but chose to separate them out for my ease of reading/maintaining.

What Objects Did You Use?

Each “category” was given it’s own Class (type of Object*).

<Deep breath …> Each time an item from a category was needed (each item on a list), I Instantiated a new Object of that Class:

To instantiate a new “Treasure” object:

Treasure thisTreasure = new Treasure();

This calls the Constructor of the Class, to create that instance of the Class (i.e. make that Object.)

e.g. Treasures are randomly chosen from “Coin”, “Art”, “Jewellery” and “Gem”. Each of these has a List of Types (Coins may be gold, silver or copper, Art may be a painting, a sculpture or a vase), and an Amount/Quality (Coins have a number, e.g. 20 Gold Crowns. A painting might be Elaborate or Exquisite, a Gem has a Cut).

Once instantiated, the Object has its set of Values, that can be called (e.g. by the Recycler Helper), to do something with (e.g. Display in a Recycler View).

Are you keeping up?

For the “Name”-type Objects (2 pieces of data each), they are all sent to the Name Adaptor to Display in the Name List (even if they are not names. It’s just what I called the 2-data section).

Quests and Locations got a little more complicated.

Each Quest Object holds several pieces of Data:

A Quest!
A Quest!

As you can see, each Quest is structured:

“You must <activity> the <descriptor> <item> before <time>. If you succeed, you will be rewarded with <reward>”

Each of these is called randomly from its String-Array. The Quest Adaptor must bind each part of this to the appropriate Recycler View.

As a complication, the Reward is called as a Treasure Object!

Locations were built in a similar manner.

Enough!

OK, that will do for today!

Let me know how much of that you understood, or if you would like some more explanations.

————-

*Java is an “Object Oriented Programming” (or “OOP”) language. Most things are “Objects”, that have “Methods” associated with them.

The Android Invasion!

(Or: How I Learnt to Stop Worrying and Love the Code)

How I Learnt to Write Apps (A Summary)

As my regular readers will know, I have been writing Apps for Android Smart Phones. Here is where I share some of my experiences, and technical details. Partly to bring my audience an informative, entertaining insight into my brain-space, and partly to clarify in my own head what is going on!

The Set-up

The first thing I need is an Environment in which to write Code. This can be done with a simple text-editor (such as Notepad, or its big brother Notepad++), but more useful is the Official IDE (Integrated Development Environment) Android Studio. A simple task to download and install.

Simple, but time-consuming. A 758MB download, which, on install, will update itself, and fetch a variety of libraries, the Java SDK, and other assorted extras.

I will also need some way of testing my code. Luckily I have a variety of old Android Phones, and a Tablet. I chose most recent phone that I am no longer using (Samsung J5). This needs drivers finding and installing, and setting some developer Options to allow me to write Apps directly to it, rather than downloading from the Google Play Store.

I could have relied up on the built-in Android Emulator,  but even on Lucretia‘s Power-House Gaming Rig, it is painfully slow to use (an hour to build and transfer a small app, rather than a couple of minutes to a real phone!)

The Inevitable “Hello World” App

Android Studio presents a default App: the ubiquitous “Hello World”. This gives me an opportunity to learn the very basics of what an Android App looks like:

  • A Main Activity file, that stores the main code (Java)
  • A Layout file, telling the App what to display on the screen (XML)
  • A set of Resource files (Pictures – known as “Drawables”, Values – constants for use in the app, codes for Colours and Styles, and many other options)
  • The IDE files – Manifest, Gradle, etc (Do not worry about these yet. Most are automatically created by the IDE)

There are a whole bunch of options when creating an App, such as which version of Android you wish to target, and what is the lowest you will be writing for, how much code you would like the IDE to start with (depending on which Template you choose), and names for your Project, App, and Files. These soon become second-nature.

To test that everything in installed and connected correctly, I hit the “Run” button, and wait for the “Gradle Build Running” message to clear …

The Initial Bug-Hunting

Obviously, things did  not go as smoothly as they should.

The IDE could not detect my phone, so I had to hunt down and install the correct drivers. I had failed to set the Developer Options correctly on my phone. The App was set to a newer version of Android than my phone used …

This was all relatively painless to fix, but put me in the mindset that I was to keep: There WILL be bugs!

But eventually, I had my App!

Hello World!
Hello World!

Writing My Own App

First, I fiddled about with some basics, to get my head around how the IDE worked, and learn the very simplest Java code.

Changing the text from “Hello World!” to “Hello Mad Dwarf!”. Using different colours. Adding a picture. Randomly choosing a Name to say “Hello” to. Inputting a name to be displayed.

None of this was without problems, but Google and Stack Overflow provided some solutions, and soon I was ready to build an actual, functional App!

Idea: an Inspirational App, providing a set of Randomly Generated Lists for use in Role-Playing Games.

Several choices needed to be made: What lists do I include? How complex? What data-structure do I use?

Reading up on data-structures, I chose to store all of my data in XML Arrays in my Resources/Strings file. This uses a very simple syntax:

<string-array name=”clothes”>

<item>Shirt</item>

<item>Trousers</item>

</string-array>

A little experimentation with layouts, and I could display a Button labelled Clothes, and have it react to being pressed.

Technical Notes

When defining the Text Label for the Button, the IDE complains if you enter the text directly. The preferred manner is to define a String, and then call that String as needed.

<string name =”clothes_button”>Clothes</string>

android:text=”@string/clothes_button”

Next, I need to “Start a new activity”, and pass it the chosen List title. To check this actually works, I make sure I have a couple more lists, and label them, and the Buttons need @ID codes, and an OnClickListener that will call the @ID of the pressed Button. So, new File. I already have “Main Activity”, so I create “Display List Activity” … and this is where the “fun” begins …

New Activities

These are launched by defining an Intent, which tells the App which activity you want to launch, and you can add “Extras” to this, which the new Activity can read. I add a “Message” that is the @ID of the button (“clothes”, “alchemy”, “monsters”, etc). This new Activity will  need its own XML Layout File (Advanced: You can define this in the Activity. For now, I don’t).

This new Activity can retrieve the “message” (“Extra”), and call the associated List (I made them the exact same name, for simplicity).

Recycling for Beginners

When I last took a foray into Java/Android, the recommended way of showing a List was to use “List View”. While checking online to remind myself how to build a List View, I found that it has been replaced by “Recycler View”, a way of “recycling” a view, to show lists … It is actually very similar to use, but more flexible (it can display in List, Grid, or Card format!)

I also need the screen to be able to Scroll, if the List goes off the bottom of the screen. Very simple. Define a Scroll View to contain the Recycler View.

I also need to use (according to Stack Overflow!) a Recycler Helper; a secondary file that does the heavy lifting of being sent a list of data. creating holders, binding the list of data to the holder and sending it back to the Activity to display.

Overall, quite a pain to learn, but very useful once done.

In Summary

  • Create several lists (String-Arrays) in Strings file.
  • Display Labelled Buttons
  • “Listen” for a button being pressed, and launch the next activity, telling it which button.
  • New Activity calls the appropriate List, and sends it to the Helper to process.
  • Display the processed List in a Scrolling Recycler View.
    Loot!
    Loot!
    Places!
    Places!

     

With a few added features (like randomising which random list to use: Cash, Jewellery, Gems or Art), I have an APP!

If you feel you’d like to write apps, but are put off by how complicated it looks, why not have a go! Yes, you will hear me screaming into the void about bugs, typos, stupid decisions (by me, the IDE developers, and Google/Android!), and generally pulling all of my hair out, but it is very rewarding!

I’m Sorry, GM, I’m Afraid I Can’t Do That!

There are many articles discussing skill-systems (or lack thereof) in RPGs. How much bonus you get, how to level-up, which you should buy.

This is  not one of those articles.

Failure
We learn from Failure, not success – Bram Stoker

Here I discuss what happens when a PC does not have a skill. Maybe the GM has called for a “History – Elven” roll, or “Electronics Repair”, or even “Climbing”. Scouring your character sheet reveals a large, conspicuous gap where that skill should be. How does your system handle that? Do you get to roll anyway, or automatically fail? Do other skills (“History – Dwarven”, or “Electronics Manufacturing”?) help at all? How relevant are your Stats?

The system our group is currently playing (FWTD) says that all Skills require a level of training, and anyone without this basic requirement (Rank 1) cannot roll, and will automatically fail. Simplistic, and ignoring the Player’s Favourite “Critical Hit”, it does distinguish between people who have invested the time and effort (XP) in learning a Skill, and those who haven’t. Most skills are based on your Intelligence score, and you roll 1d20 +4/Rank-above-One, so if you were allowed to roll, a INT 16 PC wold still have the advantage over a INT 10 PC with 2 Ranks!

Rolemaster takes a similar approach, but instead of an outright Fail, applies quite hefty penalties to unskilled characters. Rolling a d100 + Skill Bonus, and usually wanting to hit 100, unskilled applies a -30 Penalty! Even allowing for a half-decent Stat Bonus (+5 to +15), and a decent roll (70+), you are not getting very far! It does allow for “Critical Hits”, and its Exploding Dice (if you roll 95-100, you roll again and add!) can lead to some outrageous results, even for unskilled PCs.

GURPS has a complex web of default-skills. You don’t have “Electronics Repair”? You can roll “Electronics Operation” at a penalty of 3, or IQ stat at a penalty of 5. Each Skill has a list of which other skills can be substituted for each other, at what modifier. This can be a little cumbersome for novices, but a little work, and a decent character sheet, will soon see it falling into place.

Skill Web
Shadowrun Skill Web

In a similar manner, Shadowrun had its “Skill Web”, where you could trace skills to other skills, and roll with a penalty depending upon how far away on the Web they were. More cumbersome than GURPS, with little to recommend it, this was removed in later editions.

At the other end of the scale is Apocalypse World (and the ever growing list of “Powered by The Apocalypse” (PbtA) systems), that have no Skills. You have 4 Stats, rated -1 to +3, and roll 2d6 plus stat. Trying to fix that broken radio? That’ll be Sharp, unless it is a very pressured situation, when it might be Cool.

The style of game will inform (and be informed by) the Unskilled procedure. Pulp-type games, or “heroic” systems can encourage players to try actions that they are not necessarily trained in, rewarding flair and confidence, whereas “gritty”, “realistic” systems try to penalise PCs for attempting things they have no right to be doing (“I know I’m not trained in Surgery, but what’s the worst that can happen?“).

Unskilled
Try, try, and try again!

Another point to be considered is the consequence of failure. If a Fail doesn’t cost much apart from time, and allows another attempt, unskilled PCs will be wanting to Roll anyway, looking for that “Natural 20”. PbtA (and other systems) has distinct problems that arise from failed rolls (e.g. failing a Combat roll means you got hit!), and players will be more inclined to call “Oh, no! I didn’t realise it would be a HOT roll! Can I take that back? Or make it a HARD roll instead?” rather than suffer the Consequence of Failure.

Failure does not always mean “The task is completely failed”. If the GM calls for a Horse Riding roll, and your Urban Hacker has never even seen a horse before being hoisted onto one five minutes previously (no Skill Ranks), this does not mean that they sit there immobile while their team-mates ride off to the Bad Guy’s hideout, but will mean that anyone who has ridden one before (Rank 1 Skill), will get their earlier, in better shape, with a happier horse (unless they roll a Fumble – sometimes a little knowledge is a dangerous thing!)

So next time you’re wondering whether to invest your hard-won XP in a new skill, rather than pushing up an existing one, look to the system you are playing – can you roll a decent Default Skill? Does it open a new set of Tasks you were previously unable to attempt? Does it move you from Inevitable Failure to Almost Certain Failure, or do you reach Possible Success (For Easy Tasks)? Each system has different ways of approaching these things, and they can lead to quite different styles of play.