Code Overhaul 1: Arrays to Types

Declaring Types

As part of the code overhaul whilst fixing bugs and changing the map system, I figured along the way I’d make the code better so it’s easier to use for future coding and is more efficient.

The first of these changes is using User-defined types instead of my standard arrays. So I might have a few arrays like this:

global player = 1

global enemy = 2

dim HP(2)

dim MaxHP(2)

HP(player) = 700

MaxHP(player) = 700

HP(enemy)  = 900

MaxHP(enemy) = 900

These arrays are being replaced with types. Whilst, yes, it takes a bit more code to declare types, but I find it makes for tidier code, plus it reads better to me. The main advantage is when you’re declaring multiple Arrays you’re keeping track of multiple numbers, for example, I might create an Array for object numbers and there’s 7 objects, I have go to that array and adjust it if I decide to add anymore, but lets say I use arrays for those objects interacting with each other – say, arrays for storing text, then I have to go and change those arrays, lets say there’s an array for each of their stats, then I have to go and edit each of those arrays to adjust them to the same number. With user-define types the only array I need to declare is that ‘Character’ array, which can store HP, Strength, Items, Names, Speech, stats and so on (see below image and examples).

Player Stats Assigned Through a UDT

Cha(keats).HP = 700

Cha(keats).MaxHP = 700


cha(keats).name = “Keats”

cha(keats).path.shadower = 1

cha(keats).threshold.curse = 1


Scene(1).camera.x = 100

Scene(1).camera.y = 200

Scene(1).camera.z = 100

Whilst there’s a lot of code to overhaul, but I think this approach will work much better, especially with the next map system.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s