Author Topic: Notes for HD modders  (Read 7460 times)

0 Members and 1 Guest are viewing this topic.

sillytuna

  • Eufloria lacky
  • Administrator
  • Arboreal Being
  • *****
  • Thank You
  • -Given: 58
  • -Receive: 92
  • Posts: 446
    • TunaHQ
  • Eufloria: Yes
Notes for HD modders
« on: May 25, 2012, 05:13:12 PM »
EDIT: This is rather out of date. Do people want me to update it? It's also relevant for the new PC/Mac/Linux/Android versions.

Since some of you amazing people are playing with iOS maps, here's some notes. I'm just pulling some random things out of scripts here but some of it may be useful.

It's worth giving me a prod on Twitter (alex_amsel) if you have queries as I'm still across the other side of the world and will be travelling over the next few days.

lang.csv
Game text
This is exported from a Google doc as a tabbed tsc/csv file. Messages are referenced by the ID in the first column, and the message is in the second column. You can easily edit this in a text editor or in a spreadsheet (but be wary of characters being corrupted). # characters signify blank lines. {uXXXX} signifies a special character in the font such as an icon. ~ signifies a new paragraph. | signifies a new page of text.

Note that the text rendering routines don't calculate paragraphs particularly well as they were only added for limited use. More than 4 paragraphs is probably not supported and you need to try and balance paragraph lengths.

Support.lua
StartLevelLogic: First part is a quick debug hack (enabled by setting debugEnabled to true) allowing me to tap an asteroid as soon as a level starts in order to dump some seedlings on it. Second part if regular code to switch on some dark mode settings if relevant.

Debug: Prints a debug message to the console (I have no idea if you can get it to do this usefully - anyone?)

WaitMessage: Waits for a message to have completed, with an optional delay of 1 second afterwards. It also checks for if the game has finished at all times.

ClearMessage: Removes a message with an optional 2 second delay afterwards.

WaitDialog: Waits for a pop up dialog box to be closed.

WaitReal: Waits t seconds in real time

WaitGame: Waits t seconds in game time (i.e. if running at x3 speed then 1 real second = 3 game seconds)

Quit: Tells the game to exit, with a true or false parameter for has won/lost.

SetHelpAvailableStoryMode and SetTutorialButtonStoryMode enable help/tutorial buttons in non dark mode.

RulesNormal.lua
The comment at the top is incorrect - this is just the game over functionality in normal mode. Note to self, edit this file header!
The GameOver function takes care of ensuring the game finishes properly with appropriate messages and sounds. If no prefix is past, no message is displayed and the caller must take care of it, otherwise a message is put together based upon the prefex and _win/_lose, e.g. 07_win.

RulesDarkMatter.lua
As RulesNormal but the actual level end conditions are also in here, in CheckConditions. This is because they're the same in all dark matter levels.

Default.lua / DarkMatter.lua / Classic.lua
You'll have to ask Rudolf or AlexM about a lot of these settings but these are what make the game what it is! I can usually look them up in the src if someone has any particular questions and the guys don't have time tho. Default is the regular game, DM is DM(!), classic is the easy/relaxed mode (which caused nightmares...).

Level Scripts
I restructured these for iOS.

LevelSetup() - put all level specific set ups here. You can override the game mode settings here and set up the asteroids. This will be similar to the original PC version I expect. Note that the camera is not necessarily fully ready at this point.

On asteroids, there is SetProtected(true) which stops the AI attacking the asteroid (well, it should do). You can later unprotect the asteroid.

You can also enable or disable buttons here (tho also elsewhere), e.g. SetFlowerDefenseButtonAvailable. Search levels 1-14 (probably 1-6, 8, 10, 14) for examples.

SetCameraPositionToAsteroidID and SetCameraZoomNow set the camera starting position.

LevelLogic()
The logic for the level goes here. You're best off looking at levels for examples. Essentially there is a little set up, a message, then a while GameRunning() do loop.

OnAsteroidRevealed()
An asteroid has been revealed, indicated by id and owner. An owner id of 1 is the player, 0 is grey, 2+ is another enemy.

OnAsteroidTaken()
As revealed but the asteroid was taken.

CheckConditions()
Determine if the game has been won or lost, and display appropriate messages. Sometimes the GameOver routine takes care of all messages but sometimes the level is a little more particular so does it manually.

General notes - I tried to keep the scripts compatible with future non iOS versions [based on PS3, not existing PC build] hence a lot of iOS checks. However, I can't guarantee they work outside of iOS as I've not tested them so there will probably be bugs!

Also, all these functions have a standard layout, e.g. CheckConditions always exits immediately if gameFinished is true. Similarly LevelLogic calls StartLevelLogic and calls UpdateAsteroidLists for all empires on the level. It's important not to remove this code.

There are still a few minor inconsistencies but overall the levels should be reasonably clean.

« Last Edit: November 16, 2012, 10:11:50 AM by sillytuna »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Notes for iOS modders
« Reply #1 on: May 25, 2012, 05:58:12 PM »
Thanks for this!!

A massive treasure trove of valuable information... :>

So many questions...


Lets start with this one:

Tom recently posted that WaitReal() was preventing a while GameRunning() loop from looping... He did a bunch of tests and the while loop always terminates after the WaitReal command.
How does that command work?  How is it intended to be used?

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: Notes for iOS modders
« Reply #2 on: May 25, 2012, 08:33:10 PM »
As Annikk said, thank you so much, really is appreciated sillytuna.

And like Annikk, I have questions as well.

Just to let you know, I have an iPad 3, Wi-Fi 64GB

1. Is there any reason on which some code could possibly stop WaitReal() from working? But on top of not working, all the code works until it reaches WaitReal() and then nothing happens. but this is not the case for every level, I have 7 levels which work great with the WaitReal() but not on my 8th level, but I did combat this with Annikks custom timer though, see the code below, that is how I've made a slight delay before the seedlings are sent.
Code: [Select]
function LevelLogic()
StartLevelLogic()

Puzzle1 = 0
puzzletimer = GetGameTime() + 4
GetAsteroid(16).Owner = 1
GetAsteroid(16):Hide(1)


while GameRunning() do
if Puzzle1 == 1 then
if GetGameTime() > puzzletimer then
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
puzzletimer = puzzletimer + 30
end
end

if CheckPoint = 1 and GetEmpire(1).NumSeedlings == 0 then
GetAsteroid(10):AddSeedlings(1)
end

coroutine.yield()
end
end

As you can see, instead of having puzzletimer this and that, I would have loved to have used WaitReal(2) or something, but you know, you can't do everything can you.

But now, I have added this into the code.

Code: [Select]
function LevelLogic()
StartLevelLogic()

Puzzle1 = 0
puzzletimer = GetGameTime() + 4
GetAsteroid(16).Owner = 1
GetAsteroid(16):Hide(1)

if IsiOS() then -- TESTING
SelectionClear()
WaitReal(2)
SetLevelDim(true)
Message("Testing", true, 1.0, "Left")
WaitMessage(true)
SetLevelDim(false)
else
MessageBox("01_01")
WaitDialog()
end


while GameRunning() do

Notice that i'm trying to start adding some text now, but when I input that code, it does not work one bit, but after messing around with it, I realised that the WaitReal() is actually causing the problem, because when I take it out (ALSO THE SAME WITH WaitGame()). The level works. Now I'm guessing this is a Glitch/My Fault for doing something wrong during LevelSetup(), but honestly, I can't see anything different from my other levels.

So, what the heck? :P

2. SetCameraPosition(x,y) seems to be a very buggy, thats IF the player moves the position around, if the player doesn't move the position in the game then the camera will set it's position to whatever (x,y) I state. What I am not saying is moving the camera while the camera is being changed, I mean if the camera is at (0,0) already, and I swipe to (-1000,0) and I want the camera to be at (2000,2000), because I've swiped on my screen, it would just go somewhere completely different, not (2000,2000)

3. Is there actually any way of seeing what crashes a level? PC users get a error message that pops up, All i get it a shut off game :P

4. It seems I don't need the lang.csv for messages, by putting my text in the actual level itself, is that doing anything dangerous?

5. I've noticed that if I used this code:

Code: [Select]
while GetAsteroid(1).NumSeedlings < 38 do
coroutine.yield()
CheckConditions()
end

does not work at all, but this code:

Code: [Select]
while GetEmpire(1).NumSeedlings < 38 do
coroutine.yield()
CheckConditions
end

The only problem with that is that what if I want to do something after a certain asteroid has something special, this is also the same case with .NumTrees .NumDysonTrees .NumDefenseTrees, but if it's just how it is then I'll have to deal with it.

I can't think of anymore questions now but I probably will have some :D

Looking forward to some feedback :)


sillytuna

  • Eufloria lacky
  • Administrator
  • Arboreal Being
  • *****
  • Thank You
  • -Given: 58
  • -Receive: 92
  • Posts: 446
    • TunaHQ
  • Eufloria: Yes
Re: Notes for iOS modders
« Reply #3 on: May 25, 2012, 08:34:00 PM »
WaitReal() definitely shouldn't cause the game loop to quit unless CheckConditions hasn't been set up right. It's used all over the place and the code is minimal (it's a simple function defined in the source file mentioned). I'll need to look at your source.

Text - I forgot, yes, you can add text directly. If the ID isn't recognised it'll just use the text.

SetCameraPosition - camera stuff on iPad is quite different and it's very possible you can't do some things you'd like to do due to what areas are 'unlocked' for viewing. You can't just set a position, the area needs to be viewable and even then the camera needs to be in a valid area. This is all to do with the sort of fog of war/or not, and the iPad's pan controls, if you know what I mean.

I'll have to check on the other stuff AM (night time here in NZ).
« Last Edit: May 25, 2012, 08:39:18 PM by sillytuna »

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: Notes for iOS modders
« Reply #4 on: May 25, 2012, 08:38:09 PM »
So you're telling me CheckConditions HAS to be in there for WaitReal()/WaitGame() to work?

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: Notes for iOS modders
« Reply #5 on: May 25, 2012, 08:45:14 PM »
I just need to get this out of the way...

(click to show/hide)

I've been speculating and wondering what is wrong with my level for at least 4 days now, and the whole error was that I didn't put in CheckConditions(), now WaitReal() works, flipping heck. I'm glad im the first IsiOS coder (if i am, havn't seen anyone else do it) to be making all these mistakes, when theres others to help i'll have flipping experience in mistakes -.- haha!

Also

It's worth giving me a prod on Twitter (alex_amsel) if you have queries as I'm still across the other side of the world and will be travelling over the next few days.

I follow you, you follow me? :P (@ThomasBiggin)
« Last Edit: May 25, 2012, 08:48:36 PM by Tomfloria »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Notes for iOS modders
« Reply #6 on: May 25, 2012, 10:47:00 PM »
I've had loads of those moments.. :>

Mine were a lot more stupid though.

One time I spent a whole morning - 4 hours or so - trying to fix a bug with the 3D Starfield Engine.
I checked it and checked it, trying different stuff, and it all looked correct - I just couldn't figure out what was wrong.

Eventually I realised I was working on the wrong .lua file. :P

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: Notes for iOS modders
« Reply #7 on: May 26, 2012, 02:55:04 AM »
Haha Annikk, you make me laugh! I'm so gutted, now though, I can edit everything on my iPad now, since I've jailbroken it, so no more annoying PC to iPad transfers.

sillytuna

  • Eufloria lacky
  • Administrator
  • Arboreal Being
  • *****
  • Thank You
  • -Given: 58
  • -Receive: 92
  • Posts: 446
    • TunaHQ
  • Eufloria: Yes
Re: Notes for iOS modders
« Reply #8 on: May 26, 2012, 06:36:58 AM »
Yeah CheckConditions always needs to be there. That determines if the game has finished or not. You nee to roll your own CheckConditions though, unless working in DM mode.

If you have any game loops they should also always have this check in (as you'll see if I look through the code). This prevents the game ending in theory but not actually happening for the player.

Error and debug messages from LUA - these are sent to standard output. With XCode connected during dev we see messages in the console. I'm not sure if it can be done another way but I'm sure it can, although maybe only for jailbroken devices.

If your script breaks it's likely to be a typo, a missing 'then', or a command not recognised (also usually due to a typo, but the same happens if e.g. CheckConditions is missing).

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: Notes for iOS modders
« Reply #9 on: May 26, 2012, 09:19:53 AM »
Well I have CheckConditions() in every while loop just before coroutine.yield(), I realised I needed them in when I purposely killed my seedlings and because the while loop kept repeating, it couldn't carry on.

As for error messages I basically wing it, I usually figure out what's wrong though, as long as you know how to write stuff it can be a breeze :D  make updates! Haha, would love to see more stuff for this game :P

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: Notes for iOS modders
« Reply #10 on: May 28, 2012, 12:05:10 AM »
Just thought i'd post a little snippet for people with an iOS device, this is a few pictures and some explinations.

(click to show/hide)