Author Topic: Common coding tasks  (Read 26654 times)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Common coding tasks
« on: May 18, 2012, 07:15:54 PM »
Figured I'd start a thread where I (and others) give examples of program code that is likely to be used often.

Let me know if you guys have any requests!
Also let me know if you spot a mistake, or you tried some of this code and it didn't work, even in an otherwise empty level file.

0. Contents

1. Send seedlings after a delay
2. Perform an arbitary number of different tasks after different amounts of time
3. Determine whether a number is odd or even
4. Calculate the distance between the centers of two asteroids
5. Calculate the distance between the closest edges of two asteroids
6. Calculate how much send distance is required for Asteroid 1 to be able to send seedlings to Asteroid 2
7. Calculate the X and Y coordinates at which the line formed by points: [Lx1, Ly1] [Lx2, Ly2] intersects with the line formed by [Lx3, Ly3] [Lx4, Ly4]
8. Calculate the X, Y and Z coordinates at which a line, denoted by any 2 points with coordinates [Lx1, Ly1, Lz1] [Lx2, Ly2, Lz2] intersects with a plane, denoted by any 3 coordinates on that plane; [Px1, Py1, Pz1] [Px2, Py2, Pz2] [Px3, Py3, Pz3]
9. Convert a set of 2D LevelDraw Coordinates into a set of 2D ScreenDraw Coordinates
10.  Concatenate one or more variables and/or one or more strings of text into a single MessageBox



1. Send seedlings after a delay
Code: [Select]
function LevelLogic()
-- create a "latch" variable, so that the seedlings are only sent once.
once = false


-- Run this loop continuously
while GameRunning() do

-- check if enough game time has passed yet
if GetGameTime() > 3 and once == false then

-- 3 seconds have passed - Asteroid 0 should now send 50 seedlings belonging to Empire 2 to Asteroid 1.
GetAsteroid(0):SendSeedlingsToTarget(50,2,GetAsteroid(1))

-- flip the latch
once = true

end

coroutine.yield()
end
end



2. Perform an arbitary number of different tasks after different amounts of time
Code: [Select]
function LevelLogic()
-- create an "incident" variable.  This will be used to store a note of which event is due to happen next.
incident = 0

-- create a "next" variable, this will record what the Game Time should be when the next incident must be run
next = 0

-- Run this loop continuously
while GameRunning() do

-- check if it's time for the next event
if GetGameTime() > next then

-- It's time, so run the action function for the current incident
Action(incident)

-- increment the incident counter by 1
incident = incident + 1

end

coroutine.yield()
end
end

function Action(incident)

if incident == 0 then
GetAsteroid(0):AddSeedlings(10)
next = GetGameTime() + 10
elseif incident == 1 then
GetAsteroid(0):AddSeedlings(20)
next = GetGameTime() + 5
elseif incident == 2 then
GetAsteroid(0):PlantDysonTree(1)
next = GetGameTime() + 25
elseif incident == 3 then
GetAsteroid(0):SendSeedlingsToTarget(50,1,GetAsteroid(1))
next = GetGameTime() + 10
elseif incident == 4 then
SetBackdropColour(0,0,80)
next = GetGameTime() + 15
else
-- no further incidents defined
end
end



3. Determine whether an integer is odd or even
Code: [Select]
if integer % 2 == 0 then -- if the integer divided by 2 has a remainder of 0, then
--the integer is even
else
-- the integer is odd
end


4. Calculate the distance between the centers of two asteroids
Code: [Select]
function LevelLogic()

-- first lets assign the values to some variables
roid1X = GetAsteroid(1).position.X
roid1Y = GetAsteroid(1).position.Y
roid2X = GetAsteroid(2).position.X
roid2Y = GetAsteroid(2).position.Y

-- next, calculate the diffence between their X coordinates
dx = roid2X - roid1X

-- and their Y coordinates
dy = roid2Y - roid1Y

-- dx and dy are like 2 sides of a right angled triangle.
-- If you recall pythagoras, the 3rd side (hypotenuse) can be calculated with a^2 + b^2 = c^2
-- So dx^2 + dy^2 = DistanceBetweenAsteroids^2

distance = math.sqrt((dx * dx) + (dy * dy))

end



5. Calculate the distance between the closest edges of two asteroids
Code: [Select]
function LevelLogic()

-- first lets assign the values to some variables
roid1X = GetAsteroid(1).position.X
roid1Y = GetAsteroid(1).position.Y
roid2X = GetAsteroid(2).position.X
roid2Y = GetAsteroid(2).position.Y

-- next, calculate the diffence between their X coordinates
dx = roid2X - roid1X

-- and their Y coordinates
dy = roid2Y - roid1Y

-- dx and dx are like 2 sides of a right angled triangle.
-- If you recall pythagoras, the 3rd side (hypotenuse) can be calculated with a^2 + b^2 = c^2
-- So dx^2 + dy^2 = DistanceBetweenAsteroids^2

dist = math.sqrt((dx * dx) + (dy * dy))

-- dist is the distance between the asteroid centers.  To get the actual distance between their surfaces, we must subtract both radii from dist
distance = dist - GetAsteroid(1).radius - GetAsteroid(2).radius

end


6. Calculate how much send distance is required for Asteroid 1 to be able to send seedlings to Asteroid 2
Code: [Select]
function LevelLogic()

-- first lets assign the values to some variables
roid1X = GetAsteroid(1).position.X
roid1Y = GetAsteroid(1).position.Y
roid2X = GetAsteroid(2).position.X
roid2Y = GetAsteroid(2).position.Y

-- next, calculate the diffence between their X coordinates
dx = roid2X - roid1X

-- and their Y coordinates
dy = roid2Y - roid1Y

-- dx and dx are like 2 sides of a right angled triangle.
-- If you recall pythagoras, the 3rd side (hypotenuse) can be calculated with a^2 + b^2 = c^2
-- So dx^2 + dy^2 = DistanceBetweenAsteroids^2

dist = math.sqrt((dx * dx) + (dy * dy))

-- dist is the distance between the asteroid centers.  To get the minimum required SendDistance, we measure from the center of Asteroid 1 (startpoint) to the edge of Asteroid 2 (destination)
distance = dist - GetAsteroid(2).radius

end


7. Calculate the X and Y coordinates at which the line formed by points: [Lx1, Ly1] [Lx2, Ly2] intersects with the line formed by [Lx3, Ly3] [Lx4, Ly4]
Code: [Select]
-- calculate A, B and C for both lines (standard form)
A1 = Ly2-Ly1
B1 = Lx1-Lx2
C1 = A1*x1+B1*y1
A2 = Ly4-Ly3
B2 = Lx3-Lx4
C2 = A3*x3+B3*y3

-- detect if they will ever intersect..
det = A1*B2 - A2*B1

if det == 0
--Lines are parallel

else
-- intersection coordinates give as:

intersectX = ((B2*C1) - (B1*C2)) / det
intersectY = ((A1*C2) - (A2*C1)) / det

end



8. Calculate the X, Y and Z coordinates at which a line, denoted by 2 points with coordinates [Lx1, Ly1, Lz1] [Lx2, Ly2, Lz2] intersects with a plane, denoted by 3 coordinates on that plane; [Px1, Py1, Pz1] [Px2, Py2, Pz2] [Px3, Py3, Pz3]
Code: [Select]
-- get 2 vectors along the plane
-- PV1x stands for Plane Vector #1, X-coordinate
PV1x = Px2 - Px1
PV1y = Py2 - Py1
PV1z = Pz2 - Pz1

PV2x = Px3 - Px1
PV2y = Py3 - Py1
PV2z = Pz3 - Pz1

-- now find the cross product, which is a line perpendicular to the plane
-- PV1 X PV2 = normal vector!
i = (PV1y * PV2z) - (PV1z * PV2y)
j = (PV1z * PV2x) - (PV1x * PV2z)
k = (PV1x * PV2y) - (PV1y * PV2x)

-- for the line, calculate tx, ty, tz
tx = Lx2 - Lx1
ty = Ly2 - Ly1
tz = Lz2 - Lz1

-- calculate t
num = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1)))
denom = ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))
t = num / denom

-- calculate coordinates of the intersection point
intersectX = (t * tx) + Lx1
intersectY = (t * ty) + Ly1
intersectZ = (t * tz) + Lz1


9. Convert a set of 2D LevelDraw Coordinates into a set of 2D ScreenDraw Coordinates
Code: [Select]
-- where lvlX is the x-coordinate of the point in Leveldraw that must be converted, and lvlY is the y-coordinate.

screenX = (lvlX * GetCameraScale()) - (GetCameraX() * GetCameraScale()) + (GetScreenWidth() - (GetScreenWidth() / 2))
screenY = (lvly * GetCameraScale()) - (GetCameraY() * GetCameraScale()) + (GetScreenHeight() - (GetScreenHeight() / 2))


10.  Concatenate one or more variables and/or one or more strings of text into a single MessageBox
Code: [Select]
c1 = 5
d1 = 0
omg1 = "cats"

MessageBox(c1 .. d1)
-- "05"

MessageBox("Hello " .. omg1)
-- "Hello cats"

MessageBox("You have " .. c1 .. " " .. omg1 .. " and " .. d1 .. " dogs.  Clearly you must prefer " .. omg1 .. ".")
-- "You have 5 cats and 0 dogs.  Clearly you must prefer cats."
« Last Edit: May 26, 2012, 08:33:01 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #1 on: May 18, 2012, 07:54:35 PM »
Reserved
« Last Edit: May 26, 2012, 08:27:02 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #2 on: May 18, 2012, 08:50:55 PM »
Reserved
« Last Edit: May 26, 2012, 08:27:11 PM by annikk.exe »

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #3 on: May 18, 2012, 10:13:22 PM »
Put in messages :P and while loops, if that's what it's called

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #4 on: May 18, 2012, 10:40:07 PM »
Hmm, do you need an example of just a while loop?
I would have thought they were covered adequately in the beginner and intermediate guides..

(especially the intermediate guide - there is a whole section that talks about while GameRunning() do at the start of it)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #5 on: May 18, 2012, 10:42:28 PM »
And messagebox.... isn't MessageBox("Fish") self explanatory?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #6 on: May 18, 2012, 10:43:52 PM »
I could do one on concatenating variables and text into the same MessageBox I suppose... that's not obvious.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #7 on: May 18, 2012, 10:46:29 PM »
No I know how to do them XD, this is a common coding thread, I always use while loops :D

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #8 on: May 18, 2012, 10:50:58 PM »
Such as

Code: [Select]
while GetEmpire(0).NumSeedlings > 0 do --Checks to see if Empire 0's Number of Seedlings is 0 or less, can't be less than 0 though.

                        CheckConditions() --THIS IS SOMETHING I USE PERSONALLY. YOU DON'T NEED IT.

                        coroutine.yield() -- Makes this statement check over and over until Empire 0's number of seedlings is at 0
end --To end this statement

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #9 on: May 18, 2012, 10:53:33 PM »
By "common coding tasks" I mean the ones you are likely to have to do at some point, but excluding anything that is so basic that most people are likely to know about it already.

I'm also aiming to avoid duplicating anything in the beginner or intermediate guides.


I've added a concatenated messagebox guide.  :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #10 on: May 18, 2012, 10:55:55 PM »
OH.. ICUP. :D

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #11 on: May 18, 2012, 10:56:52 PM »
Also, I consider using any type of While loop other than While GameRunning() to be bad programming practice. :P

It's far far more flexible if you just have one loop running all the time, and then use conditionals to trigger code within that loop.  EG, did you see example 2 in this thread? :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #12 on: May 18, 2012, 11:02:34 PM »
I see what you mean, but isn't it easier to see your code in 1,2,3,4 (order) rather than somewhere else? :D At least easier for me

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #13 on: May 19, 2012, 12:52:09 AM »
It's slightly easier when you're doing basic things, but once you get into coding anything above beginner level, using any other kind of While loop other than while GameRunning() is likely to cause problems; you'll want to run multiple mechanics at once, but you won't be able to easily because different sections of code are looping at different times...


Hard to explain, but it's a conclusion I swiftly reached after I made the level "Return to Fluffy Land" which was my 2nd level ever.  I wrote that with lots of While loops that were triggered one after the other.  While 1 would loop for a while, then stop... then While 2 would loop for a while, then stop, then While 3 would loop...and so on.  It ended up being sooo messy, and by the end of the level I found it was restricting what I could do, so for the final loop I believe I just did While GameRunning() do, and then figured out how to run mechanics in parallel within that loop.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #14 on: May 19, 2012, 01:01:04 AM »
The alternative to using lots of While loops, as I just described, is basically outlined in example 2.
If you set up a system like that, all the events that take place are grouped together, and adding a new event is very easy.  That's a way to create sequences of events after periods of time.  There are other ways to do it... like for example you could make events/incidents an array, and store the time they should be activated in each slot.  So for example incident[0] = 5 means that the first incident happens after 5 seconds of game time.  That would allow you to input specific times, rather than "15 seconds after the previous event".

Think of any functionality that you can do with lots of while loops, and I'll show you a way to do it better with while GameRunning()

:>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #15 on: May 19, 2012, 01:20:18 AM »
I'll show you part of one of my levels


Thats in LevelLogic()

Code: [Select]
if IsiOS() then -- Defence, Find your allies
SetCameraZoom(2000)
SetCameraPosition(0,0)
SelectionClear()
WaitReal(2)
SetLevelDim(true)
Message("-Hired Defence-~Find your lost brothers and sisters, don't forget what you've learnt~This is unknown territory", true, 1.0, "Top")
WaitMessage(true)
SetLevelDim(false)
else
MessageBox("01_01")
WaitDialog()
end

if IsiOS() then -- Be Prepared First
WaitReal(2)
Message("There should be enough seedlings to plant 4 Defence Trees, and maybe more,~Search the Asteroid Belt for seedlings.", true, 1.0, "Top")
WaitMessage(true)
else
MessageBox("01_02")
WaitDialog()
end

while GetEmpire(1).NumSeedlings < 42 do
CheckConditions()
coroutine.yield()
end

if IsiOS() then -- Asteroid Belts are everchanging
WaitReal(2)
Message("Now you have enough seedlings to create 4 Defence Trees~Find an Asteroid that supports planting.", true, 1.0, "Top")
WaitMessage(true)
else
MessageBox("01_02")
WaitDialog()
end

while GetEmpire(1).NumTrees < 1 do
CheckConditions()
coroutine.yield()
end

This is whats in my GameRunning() loop

Code: [Select]
while GameRunning() do
CheckConditions()
coroutine.yield()
end

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #16 on: May 19, 2012, 01:20:50 AM »
Show me what you can do baby :D

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Common coding tasks
« Reply #17 on: May 19, 2012, 01:33:59 AM »
The odd/even check can be simplified to:
Code: [Select]
if x % 2 == 1 then
  //is odd
else
  //is even
end

It misses out the nasty divides.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #18 on: May 19, 2012, 02:03:12 AM »
Ooh.  What does that % do? :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #19 on: May 19, 2012, 02:53:12 AM »
Well first let me point out what your method doesn't let you do;

You can't run any kind of additional mechanics during this sequence of delays that you have
EG you couldn't run gravity, or an AI, or a parallax/starfield engine, at the same time as this stuff.


So if you only ever want to make levels that are a sequence of events seperated by delays, your method works fine and is quite intuitive.  However, if you want to progress beyond that, it's worth figuring out how to do it in a while GameRunning() loop.



You didn't include your entire level so I'm guessing large parts of it, but here goes:

Code: [Select]
function LevelSetup()
SetCameraZoom(2000)
SetCameraPosition(0,0)
if IsiOS() then
SelectionClear()
end
latch = {}
latch[0] = false
latch[1] = false
latch[2] = false
end

function IsiOS()
return false
-- i can't make it run without defining this function...  it seems like IsiOS isn't recognised on my older PC version.
end

function CheckConditions()
-- presumably some code goes in here..
end

function LevelLogic()

while GameRunning() do -- Run this loop continuously
if GetGameTime() > 2 and latch[0] == false then
latch[0] = true
if IsiOS() then
SetLevelDim(true)
Message("-Hired Defence-~Find your lost brothers and sisters, don't forget what you've learnt~This is unknown territory", true, 1.0, "Top")
WaitMessage(true)
SetLevelDim(false)
else
SetVignetteAlpha(255)
MessageBox("-Hired Defence-                                             Find your lost brothers and sisters, don't forget what you've learnt.  This is unknown territory")
Pause()
WaitDialog()
Unpause()
SetVignetteAlpha(255)
end
end

if GetGameTime() > 4 and latch[1] == false then
latch[1] = true
if IsiOS() then
Message("There should be enough seedlings to plant 4 Defence Trees, and maybe more,~Search the Asteroid Belt for seedlings.", true, 1.0, "Top")
WaitMessage(true)
else
MessageBox("There should be enough seedlings to plant 4 Defence Trees, and maybe more.  Search the Asteroid Belt for seedlings.")
Pause()
WaitDialog()
Unpause()
end
end

if GetEmpire(1).NumSeedlings < 42 or GetEmpire(1).NumTrees < 1 then
CheckConditions() -- No idea what this does but you included it, so I will too
end

if GetEmpire(1).NumSeedlings > 42 and latch[2] == false then
latch[2] = true
if IsiOS() then
Message("Now you have enough seedlings to create 4 Defence Trees~Find an Asteroid that supports planting.", true, 1.0, "Top")
else
MessageBox("Now you have enough seedlings to create 4 Defence Trees.  Find an Asteroid that supports planting.")
end
end

coroutine.yield()
end
end


I still can't make IsiOS() work by the way.

I'll look for a way to fix that problem now..

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #20 on: May 19, 2012, 02:57:08 AM »
Not particularly tidy but it works. :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #21 on: May 19, 2012, 02:57:51 AM »
So ISiOS() crashes your game?

CheckConditions btw is if something is something it will quit true or false

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #22 on: May 19, 2012, 03:22:13 AM »
So ISiOS() crashes your game?

Yes, it does.

And it's impossible to test if it exists without running it, and if you try to run it on PC, it crashes.

So it seems that won't work... however.. I have another plan.

Ipad3 resolution is 2048 x 1536 and Ipad 1 and 2 are both 1024 × 768.

2048 x 1536 is a resolution that is basically never used on a PC/Mac, as far as I know.  And 1024 x 768 is quite a low resolution for a PC... it's also 3/4 aspect ratio which is much less common than the widescreen 16:9 and 16:10 screens that tend to be used on computers these days.


So I think we could probably build a replacement function to put in our levels that will work on both PC and iPad.
The function would test the screen width and height to determine what platform it was on.

Something like this:

Code: [Select]
function IsThisiOS()
if GetScreenWidth() == 2048 or GetScreenWidth() == 1024 then
if GetScreenHeight() == 1536 or GetScreenHeight() == 768 then
return true
else
return false
end
else
return false
end
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #23 on: May 19, 2012, 03:23:19 AM »
I'll set up a test level that we can both try. :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #24 on: May 19, 2012, 03:26:25 AM »
Ok, I get PC detected.

What do you get? :>


Code: [Select]
function LevelSetup()

Globals.G.Asteroids=1

end


function LevelLogic()

if IsThisiOS() then
Message("iPad detected", true, 1.0, "Top")
else
MessageBox("PC detected")
end

end


function IsThisiOS()
if GetScreenWidth() == 2048 or GetScreenWidth() == 1024 then
if GetScreenHeight() == 1536 or GetScreenHeight() == 768 then
return true
else
return false
end
else
return false
end
end

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Common coding tasks
« Reply #25 on: May 19, 2012, 03:54:38 AM »
% called Modulo is kinda hard to explain with simple words, instead you can look at some examples:

Code: [Select]
1 % 2 = 1
2 % 2 = 0
0 % 2 = 0
77 % 7 = 0
69 % 7 = 6

This is what I get out of using it, it basically counts down how far away you are from the fraction of the first number. I don't know of an easy way to explain it, sorry...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #26 on: May 19, 2012, 04:09:38 AM »
Ah cool... it returns the remainder of dividing the two results. :>

So if I do...

Code: [Select]
if x % 2 == 1 then
I'm saying "if x divided by two has a remainder of 1, then"

Then x must be odd :>
If it didn't have a remainder of 1, it must be even.

Fluffy understanding now.



Did you try the IsThisiOS() code? :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Common coding tasks
« Reply #27 on: May 19, 2012, 04:11:21 AM »
It's kinda nifty to use when you want to skip out some numbers, but include the others without using tons of if statements :)

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #28 on: May 19, 2012, 04:13:03 AM »
You might like this :D

(click to show/hide)

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #29 on: May 19, 2012, 04:16:28 AM »
Just to help you through the Message options aswell

Code: [Select]
Message("iPad detected", true/false, 0 to 1.0, "Top/Bottom/Centre/Left/Right")


Urm, I don't know if you can go any higher than 1.0, but thats basically the size, not transparency which I thought.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #30 on: May 19, 2012, 08:43:17 AM »


Excellent :>

We can use that instead of IsiOS() then.. and it will work on both platforms. :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #31 on: May 19, 2012, 08:54:34 AM »
I'm going to test that in one of my levels now then :D change all the ISiOS() give me a second

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #32 on: May 19, 2012, 09:06:38 AM »
Sir, could you test this out?

Code: [Select]
function LevelSetup()
--SetBackdropColour(8/255,8/255,20/255)
SetBackdropColour(225/255,225/255,225/255)

--Special thanks to Aino, Pilchard123, Alex and Annikk.exe's Guides and Helps, Without them I wouldn't have been inspired to create this custom iPad
--campaign, also obviously, without the Game, none of this would have been possible. The Creator of this level/story is Tomfloria.
--Remember this though when searching through this code, (Aino) :D I am a beginner, and the code might be messy
--But that isn't my concern, if you can clean it up, so that it works exactly the same, then go ahead, and send me
--a PM on the Eufloria Forums at http://www.dyson-game.com/smf/index.php?board=3.0

if IsThIsThisiOS() then
SetMessageDarkMode(true)
end

if IsThIsThisiOS() then
    Globals():Get("Asteroids"):Set("RadiusPowerRule",2)
Globals():Get("Asteroids"):Set("SizeFromEnergy",230)
Globals():Get("Asteroids"):Set("SizeFromStrength",230)
Globals():Get("Asteroids"):Set("SizeFromSpeed",240)
Globals():Get("Asteroids"):Set("MinCoreHealth",75)
Globals():Get("Asteroids"):Set("MaxCoreHealth",350)
Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2.5)
    Globals():Get("Asteroids"):Set("MinSendDistance",3500)
    Globals():Get("Asteroids"):Set("MaxSendDistance",5500)
    Globals():Get("Asteroids"):Set("SendPowerRule",2.0)
Globals():Get("Asteroids"):Set("SpawnCap", 40)

Globals():Get("Structures"):Set("LevelDuration1",15)
Globals():Get("Structures"):Set("LevelDuration2",30)
Globals():Get("Structures"):Set("LevelDuration3",60)
Globals():Get("Structures"):Set("LevelDuration4",100)
Globals():Get("Structures"):Set("SpawnTime1",15)
Globals():Get("Structures"):Set("SpawnTime2",12)
Globals():Get("Structures"):Set("SpawnTime3",10)
Globals():Get("Structures"):Set("SpawnTime4",8)

Globals():Get("Flowers"):Set("Available",0)

Globals():Get("Game"):Set("EnemyFactionsMin",0)
Globals():Get("Game"):Set("EnemyFactionsMax",0)
Globals():Get("Game"):Set("MinAsteroidSeparation",1500)
Globals():Get("Game"):Set("MaxAsteroidNeighbourDist",6000)
Globals():Get("Game"):Set("GreysProbability",0)

else

Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
end

--0 Starting Asteroid
a = AddAsteroidWithAttribs(5000,2000, math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 3
s = a:AddDysonTree()
s = a:AddDysonTree()
a:AddSeedlings(30)
a.Moveable = false

--1
a = AddAsteroidWithAttribs(math.random(-4000,9000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--2
a = AddAsteroidWithAttribs(math.random(-4000,9000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 2
a:SetGraceTime(1000)
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a.Moveable = true
a:Hide(1)

--3
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--4
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 1
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--5
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:SetGraceTime(0)
a:AddSeedlings(math.random(20,40))
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:Hide(1)

--6
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--7
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--8
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(2,4)
a.Moveable = true
a:SetGraceTime(4000)
a:AddSeedlings(math.random(20,40))
a:SetRadius(math.random(500,1000))
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:Hide(1)

--9
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--10
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:SetGraceTime(200)
s = a:AddDysonTree()
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a:Hide(1)

--11
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 0
a:SetProtected(true)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a.Moveable = true
a:Hide(1)

--12
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a:SetGraceTime(50)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a.Moveable = true
a:Hide(1)

--13
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--14
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(3,4)
a.Moveable = true
a:SetGraceTime(200)
s = a:AddDysonTree()
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a:Hide(1)

--15
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--16
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--17  Enemy Sprawl Asteroid
a = AddAsteroidWithAttribs(math.random(-30000,-25000),math.random(-20000,-10000), math.random(10,10) / 10,math.random(10,10) / 10,math.random(10,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 6
a.Moveable = true
a:Hide(1)
a:SetGraceTime(9999999)
a:AddSeedlings(math.random(40,60))
a:SetRadius(1500)

SetDysonTreeButtonAvailable(true)
SetDefenseTreeButtonAvailable(true)
SetFlowerDefenseButtonAvailable(false)
SetFlowerSeederButtonAvailable(false)
SetTerraformingButtonAvailable(false)
SetBeaconButtonAvailable(false)

if IsThIsThisiOS() then
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)

SetSpeedSwitchAvailable(true)
SetSendModeScoutAvailable(true)
SetSendModeUnitsSelectorAvailable(true)

SetSendModeButtonAvailable(true)
SetSendModeHoldAvailable(true)
SetSendModeDragAvailable(true)
else
SetTreeInfoAvailable(true)
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)
end

SetCameraPosition(5000,2000)

end

function LevelLogic()
StartLevelLogic()

foundAsteroidbarron11 = 0

GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDefenseTree()
GetAsteroid(17):AddDefenseTree()
GetAsteroid(17):AddDefenseTree()

CheckConditions()
WaitReal(4)
SetBackdropColour(8/255,8/255,20/255)

if IsThIsThisiOS() then -- Offerings
SelectionClear()
WaitReal(2)
SetLevelDim(true)
Message("-Ordered Strike-", true, 1.0, "Top")
WaitMessage(true)
SetLevelDim(false)
else
MessageBox("-Ordered Strike-")
WaitDialog()
end

if IsThIsThisiOS() then -- Use The Seedlings
WaitReal(1)
Message("Use the seedlings I have given you to conquer this belt.", true, 1.0, "Top")
WaitMessage(true)
else
MessageBox("Use the seedlings I have given you to conquer this belt.")
WaitDialog()
end

while foundAsteroidbarron11 == 0 do
CheckConditions()
coroutine.yield()
end

if IsThisiOS() then -- Beacon
WaitReal(1)
Message("You have found an Unstable Asteroid,~Click on any asteroid you own, and press the {u57345} Beacon Button", true, 1.0, "Top")
SetBeaconButtonAvailable(true)
WaitMessage(true)
else
MessageBox("You have found an Unstable Asteroid,~Click on any asteroid you own, and press the {u57345} Beacon Button")
WaitDialog()
end

if IsThisiOS() then -- Beacon Explination
WaitReal(1)
Message("Then Select the Unstable Asteroid~This will send any newly created seedlings to this Asteroid automatically.", true, 1.0, "Top")
SetBeaconButtonAvailable(true)
WaitMessage(true)
else
MessageBox("Then Select the Unstable Asteroid~This will send any newly created seedlings to this Asteroid automatically.")
WaitDialog()
end

while GameRunning() do
CheckConditions()
coroutine.yield()
end

end

function CheckConditions()
if gameFinished then
return
end

if GetEmpire(1):GetNumOwnedAsteroids() == GetNumAsteroids() then
if IsThisiOS() then
GameOver(true, "")
Message("You successfully taken this belt.~Well Done", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(true)
else
MessageBox("You successfully taken this belt.~Well Done")
GameOver(true, "")
Quit(true)
end
end

if GetEmpire(1).NumDysonTrees == 0 and GetEmpire(1).NumSeedlings == 0 then
if IsThisiOS() then
GameOver(false, "")
Message("You have failed to complete the tasks.", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(false)
else
MessageBox("You have failed to complete the tasks.")
GameOver(false, "")
Quit(false)
end
end
end

function OnAsteroidRevealed(id, owner)
if id == 11 then
foundAsteroidbarron11 = 1
end
end

function IsThIsThisiOS()
if GetScreenWidth() == 2048 or GetScreenWidth() == 1024 then
if GetScreenHeight() == 1536 or GetScreenHeight() == 768 then
return true
else
return false
end
else
return false
end
end

It works fine on my iPad

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #33 on: May 19, 2012, 09:13:44 AM »
Also would you mind telling me what the PC version currently offers

Dyson Tree
Defense Tree
Terraforming Tree
Beacon Tree
Flower Pod
Flower Pod that makes Defense Pods
Flower Pod that makes super seedlings (glowing ones)

Just because my Custom Story, actually has a story to it, and it makes use of the features available in the iOS version, if were cross platforming levels from iPad to PC, then I'd have to create another story line, similar but without mentioning certain stuff, which is alright I guess, but annoying :P

BUT! since I know I can do this now, I will update that level that I posted on the forums to be tested, as I really need feedback, I'll do it tomorrow so that it works with PC users properly

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #34 on: May 19, 2012, 09:19:35 AM »
Been looking through my Tower Defense type level, and wanted to ask you a question

Code: [Select]
if IsThisiOS() and stage == 1 then --20 Seedlings, 2 Asteroids, All At Once
WaitReal(25)
GetAsteroid(7):SetGraceTime(0)
GetAsteroid(7):SendSeedlingsToTarget(0,10,GetAsteroid(3))
GetAsteroid(8):SetGraceTime(0)
GetAsteroid(8):SendSeedlingsToTarget(0,10,GetAsteroid(4))
GetAsteroid(7):SetGraceTime(99999999)
GetAsteroid(8):SetGraceTime(99999999)
WaitReal(1)
stage = 2
else
--NEEDS EDITING FOR PC VERSION, NEED TO CREATE DELAY WHICH MATCHES WaitReal(25)
end

How would I make a similar delay WaitReal(25) for PC?

or should I just paste this at the bottom?

Code: [Select]
function WaitReal(t)
t = t + GetRealTime()
while GetRealTime() < t do
CheckConditions()
coroutine.yield()
end
end

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Common coding tasks
« Reply #35 on: May 19, 2012, 05:01:07 PM »
I hate to keep telling you that you've overkilled some stuff, but that IsThisiOS() function is a little big and unwieldy, surely? It also makes some nasty assumptions. Does the crash-prevention stuff that I posted somewhere work?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #36 on: May 23, 2012, 06:09:07 PM »
Sir, could you test this out?

Code: [Select]
function LevelSetup()
--SetBackdropColour(8/255,8/255,20/255)
SetBackdropColour(225/255,225/255,225/255)

--Special thanks to Aino, Pilchard123, Alex and Annikk.exe's Guides and Helps, Without them I wouldn't have been inspired to create this custom iPad
--campaign, also obviously, without the Game, none of this would have been possible. The Creator of this level/story is Tomfloria.
--Remember this though when searching through this code, (Aino) :D I am a beginner, and the code might be messy
--But that isn't my concern, if you can clean it up, so that it works exactly the same, then go ahead, and send me
--a PM on the Eufloria Forums at http://www.dyson-game.com/smf/index.php?board=3.0

if IsThIsThisiOS() then
SetMessageDarkMode(true)
end

if IsThIsThisiOS() then
    Globals():Get("Asteroids"):Set("RadiusPowerRule",2)
Globals():Get("Asteroids"):Set("SizeFromEnergy",230)
Globals():Get("Asteroids"):Set("SizeFromStrength",230)
Globals():Get("Asteroids"):Set("SizeFromSpeed",240)
Globals():Get("Asteroids"):Set("MinCoreHealth",75)
Globals():Get("Asteroids"):Set("MaxCoreHealth",350)
Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2.5)
    Globals():Get("Asteroids"):Set("MinSendDistance",3500)
    Globals():Get("Asteroids"):Set("MaxSendDistance",5500)
    Globals():Get("Asteroids"):Set("SendPowerRule",2.0)
Globals():Get("Asteroids"):Set("SpawnCap", 40)

Globals():Get("Structures"):Set("LevelDuration1",15)
Globals():Get("Structures"):Set("LevelDuration2",30)
Globals():Get("Structures"):Set("LevelDuration3",60)
Globals():Get("Structures"):Set("LevelDuration4",100)
Globals():Get("Structures"):Set("SpawnTime1",15)
Globals():Get("Structures"):Set("SpawnTime2",12)
Globals():Get("Structures"):Set("SpawnTime3",10)
Globals():Get("Structures"):Set("SpawnTime4",8)

Globals():Get("Flowers"):Set("Available",0)

Globals():Get("Game"):Set("EnemyFactionsMin",0)
Globals():Get("Game"):Set("EnemyFactionsMax",0)
Globals():Get("Game"):Set("MinAsteroidSeparation",1500)
Globals():Get("Game"):Set("MaxAsteroidNeighbourDist",6000)
Globals():Get("Game"):Set("GreysProbability",0)

else

Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
end

--0 Starting Asteroid
a = AddAsteroidWithAttribs(5000,2000, math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 3
s = a:AddDysonTree()
s = a:AddDysonTree()
a:AddSeedlings(30)
a.Moveable = false

--1
a = AddAsteroidWithAttribs(math.random(-4000,9000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--2
a = AddAsteroidWithAttribs(math.random(-4000,9000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 2
a:SetGraceTime(1000)
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a.Moveable = true
a:Hide(1)

--3
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--4
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 1
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--5
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:SetGraceTime(0)
a:AddSeedlings(math.random(20,40))
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:Hide(1)

--6
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--7
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--8
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(2,4)
a.Moveable = true
a:SetGraceTime(4000)
a:AddSeedlings(math.random(20,40))
a:SetRadius(math.random(500,1000))
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:Hide(1)

--9
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--10
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:SetGraceTime(200)
s = a:AddDysonTree()
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a:Hide(1)

--11
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 0
a:SetProtected(true)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a.Moveable = true
a:Hide(1)

--12
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a:SetGraceTime(50)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a.Moveable = true
a:Hide(1)

--13
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--14
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(3,4)
a.Moveable = true
a:SetGraceTime(200)
s = a:AddDysonTree()
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a:Hide(1)

--15
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--16
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--17  Enemy Sprawl Asteroid
a = AddAsteroidWithAttribs(math.random(-30000,-25000),math.random(-20000,-10000), math.random(10,10) / 10,math.random(10,10) / 10,math.random(10,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 6
a.Moveable = true
a:Hide(1)
a:SetGraceTime(9999999)
a:AddSeedlings(math.random(40,60))
a:SetRadius(1500)

SetDysonTreeButtonAvailable(true)
SetDefenseTreeButtonAvailable(true)
SetFlowerDefenseButtonAvailable(false)
SetFlowerSeederButtonAvailable(false)
SetTerraformingButtonAvailable(false)
SetBeaconButtonAvailable(false)

if IsThIsThisiOS() then
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)

SetSpeedSwitchAvailable(true)
SetSendModeScoutAvailable(true)
SetSendModeUnitsSelectorAvailable(true)

SetSendModeButtonAvailable(true)
SetSendModeHoldAvailable(true)
SetSendModeDragAvailable(true)
else
SetTreeInfoAvailable(true)
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)
end

SetCameraPosition(5000,2000)

end

function LevelLogic()
StartLevelLogic()

foundAsteroidbarron11 = 0

GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDefenseTree()
GetAsteroid(17):AddDefenseTree()
GetAsteroid(17):AddDefenseTree()

CheckConditions()
WaitReal(4)
SetBackdropColour(8/255,8/255,20/255)

if IsThIsThisiOS() then -- Offerings
SelectionClear()
WaitReal(2)
SetLevelDim(true)
Message("-Ordered Strike-", true, 1.0, "Top")
WaitMessage(true)
SetLevelDim(false)
else
MessageBox("-Ordered Strike-")
WaitDialog()
end

if IsThIsThisiOS() then -- Use The Seedlings
WaitReal(1)
Message("Use the seedlings I have given you to conquer this belt.", true, 1.0, "Top")
WaitMessage(true)
else
MessageBox("Use the seedlings I have given you to conquer this belt.")
WaitDialog()
end

while foundAsteroidbarron11 == 0 do
CheckConditions()
coroutine.yield()
end

if IsThisiOS() then -- Beacon
WaitReal(1)
Message("You have found an Unstable Asteroid,~Click on any asteroid you own, and press the {u57345} Beacon Button", true, 1.0, "Top")
SetBeaconButtonAvailable(true)
WaitMessage(true)
else
MessageBox("You have found an Unstable Asteroid,~Click on any asteroid you own, and press the {u57345} Beacon Button")
WaitDialog()
end

if IsThisiOS() then -- Beacon Explination
WaitReal(1)
Message("Then Select the Unstable Asteroid~This will send any newly created seedlings to this Asteroid automatically.", true, 1.0, "Top")
SetBeaconButtonAvailable(true)
WaitMessage(true)
else
MessageBox("Then Select the Unstable Asteroid~This will send any newly created seedlings to this Asteroid automatically.")
WaitDialog()
end

while GameRunning() do
CheckConditions()
coroutine.yield()
end

end

function CheckConditions()
if gameFinished then
return
end

if GetEmpire(1):GetNumOwnedAsteroids() == GetNumAsteroids() then
if IsThisiOS() then
GameOver(true, "")
Message("You successfully taken this belt.~Well Done", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(true)
else
MessageBox("You successfully taken this belt.~Well Done")
GameOver(true, "")
Quit(true)
end
end

if GetEmpire(1).NumDysonTrees == 0 and GetEmpire(1).NumSeedlings == 0 then
if IsThisiOS() then
GameOver(false, "")
Message("You have failed to complete the tasks.", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(false)
else
MessageBox("You have failed to complete the tasks.")
GameOver(false, "")
Quit(false)
end
end
end

function OnAsteroidRevealed(id, owner)
if id == 11 then
foundAsteroidbarron11 = 1
end
end

function IsThIsThisiOS()
if GetScreenWidth() == 2048 or GetScreenWidth() == 1024 then
if GetScreenHeight() == 1536 or GetScreenHeight() == 768 then
return true
else
return false
end
else
return false
end
end

It works fine on my iPad

Doesn't work fine on my PC I'm afraid.




As the error message says, Line 170 contains the problem:

Code: [Select]
--11
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 0
a:SetProtected(true)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a.Moveable = true
a:Hide(1)

The line a:SetProtected(true) is causing a problem.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #37 on: May 23, 2012, 06:11:08 PM »
I don't think SetProtected works on PC.
What is the command supposed to do?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #38 on: May 23, 2012, 06:19:14 PM »
Here's a tidied version.
Haven't changed any code, just tidied up the tabs and stuff. :>


Code: [Select]
function LevelSetup()
--SetBackdropColour(8/255,8/255,20/255)
SetBackdropColour(225/255,225/255,225/255)

--Special thanks to Aino, Pilchard123, Alex and Annikk.exe's Guides and Helps, Without them I wouldn't have been inspired to create this custom iPad
--campaign, also obviously, without the Game, none of this would have been possible. The Creator of this level/story is Tomfloria.
--Remember this though when searching through this code, (Aino) :D I am a beginner, and the code might be messy
--But that isn't my concern, if you can clean it up, so that it works exactly the same, then go ahead, and send me
--a PM on the Eufloria Forums at http://www.dyson-game.com/smf/index.php?board=3.0

if IsThIsThisiOS() then
SetMessageDarkMode(true)
end

if IsThIsThisiOS() then
Globals():Get("Asteroids"):Set("RadiusPowerRule",2)
Globals():Get("Asteroids"):Set("SizeFromEnergy",230)
Globals():Get("Asteroids"):Set("SizeFromStrength",230)
Globals():Get("Asteroids"):Set("SizeFromSpeed",240)
Globals():Get("Asteroids"):Set("MinCoreHealth",75)
Globals():Get("Asteroids"):Set("MaxCoreHealth",350)
Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2.5)
Globals():Get("Asteroids"):Set("MinSendDistance",3500)
Globals():Get("Asteroids"):Set("MaxSendDistance",5500)
Globals():Get("Asteroids"):Set("SendPowerRule",2.0)
Globals():Get("Asteroids"):Set("SpawnCap", 40)

Globals():Get("Structures"):Set("LevelDuration1",15)
Globals():Get("Structures"):Set("LevelDuration2",30)
Globals():Get("Structures"):Set("LevelDuration3",60)
Globals():Get("Structures"):Set("LevelDuration4",100)
Globals():Get("Structures"):Set("SpawnTime1",15)
Globals():Get("Structures"):Set("SpawnTime2",12)
Globals():Get("Structures"):Set("SpawnTime3",10)
Globals():Get("Structures"):Set("SpawnTime4",8)

Globals():Get("Flowers"):Set("Available",0)

Globals():Get("Game"):Set("EnemyFactionsMin",0)
Globals():Get("Game"):Set("EnemyFactionsMax",0)
Globals():Get("Game"):Set("MinAsteroidSeparation",1500)
Globals():Get("Game"):Set("MaxAsteroidNeighbourDist",6000)
Globals():Get("Game"):Set("GreysProbability",0)

else

Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
end

--0 Starting Asteroid
a = AddAsteroidWithAttribs(5000,2000, math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 3
s = a:AddDysonTree()
s = a:AddDysonTree()
a:AddSeedlings(30)
a.Moveable = false

--1
a = AddAsteroidWithAttribs(math.random(-4000,9000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--2
a = AddAsteroidWithAttribs(math.random(-4000,9000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 2
a:SetGraceTime(1000)
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a.Moveable = true
a:Hide(1)

--3
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--4
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 1
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--5
a = AddAsteroidWithAttribs(math.random(-4000,15000),math.random(1000,3000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 3
a.Moveable = true
a:SetGraceTime(0)
a:AddSeedlings(math.random(20,40))
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:Hide(1)

--6
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--7
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--8
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(2,4)
a.Moveable = true
a:SetGraceTime(4000)
a:AddSeedlings(math.random(20,40))
a:SetRadius(math.random(500,1000))
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:Hide(1)

--9
a = AddAsteroidWithAttribs(math.random(-10000,-3000),math.random(2000,8000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--10
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:SetGraceTime(200)
s = a:AddDysonTree()
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a:Hide(1)

--11
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 1
a.TreeCap = 0
a:SetProtected(true)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a.Moveable = true
a:Hide(1)

--12
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a:SetGraceTime(50)
s = a:AddDefenseTree()
s = a:AddDefenseTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a.Moveable = true
a:Hide(1)

--13
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--14
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(3,4)
a.Moveable = true
a:SetGraceTime(200)
s = a:AddDysonTree()
s = a:AddDysonTree()
s = a:AddDefenseTree()
a:AddSeedlings(math.random(20,40))
a:Hide(1)

--15
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--16
a = AddAsteroidWithAttribs(math.random(-30000,-10000),math.random(-20000,-10000), math.random(1,10) / 10,math.random(1,10) / 10,math.random(1,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = math.random(1,4)
a.Moveable = true
a:Hide(1)
a:SetRadius(math.random(500,1000))

--17  Enemy Sprawl Asteroid
a = AddAsteroidWithAttribs(math.random(-30000,-25000),math.random(-20000,-10000), math.random(10,10) / 10,math.random(10,10) / 10,math.random(10,10) / 10) --BARRENROID
a.Owner = 0
a.TreeCap = 6
a.Moveable = true
a:Hide(1)
a:SetGraceTime(9999999)
a:AddSeedlings(math.random(40,60))
a:SetRadius(1500)

SetDysonTreeButtonAvailable(true)
SetDefenseTreeButtonAvailable(true)
SetFlowerDefenseButtonAvailable(false)
SetFlowerSeederButtonAvailable(false)
SetTerraformingButtonAvailable(false)
SetBeaconButtonAvailable(false)

if IsThIsThisiOS() then
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)

SetSpeedSwitchAvailable(true)
SetSendModeScoutAvailable(true)
SetSendModeUnitsSelectorAvailable(true)

SetSendModeButtonAvailable(true)
SetSendModeHoldAvailable(true)
SetSendModeDragAvailable(true)
else
SetTreeInfoAvailable(true)
SetEnemyInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)
end

SetCameraPosition(5000,2000)

end

function LevelLogic()
StartLevelLogic()

foundAsteroidbarron11 = 0

GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDysonTree()
GetAsteroid(17):AddDefenseTree()
GetAsteroid(17):AddDefenseTree()
GetAsteroid(17):AddDefenseTree()

CheckConditions()
WaitReal(4)
SetBackdropColour(8/255,8/255,20/255)

if IsThIsThisiOS() then -- Offerings
SelectionClear()
WaitReal(2)
SetLevelDim(true)
Message("-Ordered Strike-", true, 1.0, "Top")
WaitMessage(true)
SetLevelDim(false)
else
MessageBox("-Ordered Strike-")
WaitDialog()
end

if IsThIsThisiOS() then -- Use The Seedlings
WaitReal(1)
Message("Use the seedlings I have given you to conquer this belt.", true, 1.0, "Top")
WaitMessage(true)
else
MessageBox("Use the seedlings I have given you to conquer this belt.")
WaitDialog()
end

while foundAsteroidbarron11 == 0 do
CheckConditions()
coroutine.yield()
end

if IsThisiOS() then -- Beacon
WaitReal(1)
Message("You have found an Unstable Asteroid,~Click on any asteroid you own, and press the {u57345} Beacon Button", true, 1.0, "Top")
SetBeaconButtonAvailable(true)
WaitMessage(true)
else
MessageBox("You have found an Unstable Asteroid,~Click on any asteroid you own, and press the {u57345} Beacon Button")
WaitDialog()
end

if IsThisiOS() then -- Beacon Explination
WaitReal(1)
Message("Then Select the Unstable Asteroid~This will send any newly created seedlings to this Asteroid automatically.", true, 1.0, "Top")
SetBeaconButtonAvailable(true)
WaitMessage(true)
else
MessageBox("Then Select the Unstable Asteroid~This will send any newly created seedlings to this Asteroid automatically.")
WaitDialog()
end

while GameRunning() do
CheckConditions()
coroutine.yield()
end

end

function CheckConditions()
if gameFinished then
return
end

if GetEmpire(1):GetNumOwnedAsteroids() == GetNumAsteroids() then
if IsThisiOS() then
GameOver(true, "")
Message("You successfully taken this belt.~Well Done", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(true)
else
MessageBox("You successfully taken this belt.~Well Done")
GameOver(true, "")
Quit(true)
end
end

if GetEmpire(1).NumDysonTrees == 0 and GetEmpire(1).NumSeedlings == 0 then
if IsThisiOS() then
GameOver(false, "")
Message("You have failed to complete the tasks.", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(false)
else
MessageBox("You have failed to complete the tasks.")
GameOver(false, "")
Quit(false)
end
end
end

function OnAsteroidRevealed(id, owner)
if id == 11 then
foundAsteroidbarron11 = 1
end
end

function IsThIsThisiOS()
if GetScreenWidth() == 2048 or GetScreenWidth() == 1024 then
if GetScreenHeight() == 1536 or GetScreenHeight() == 768 then
return true
else
return false
end
else
return false
end
end



By the way, I've noticed you always specify the background colour like this:


Code: [Select]
SetBackdropColour(225/255,225/255,225/255)
Do you realise that will just resolve to SetBackdropColour(0.88,0.88,0.88) ?
Because 225 divided by 255 = 0.88

So you'll end up with an amount that is slightly below 1.
Since 0 = no colour and 255 = full colour, you'll end up with a black background.  Actually it will be very very very dark grey, but probably indistinguishable from black.


You can also just wrote the command like this:

Code: [Select]
SetBackdropColour(0,0,0)
That just sets the background to jet black.  And it makes the command shorter and tidier.  :>  There's no need to use those divides..

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #39 on: May 23, 2012, 07:04:27 PM »
I don't know why the backdrop is like that, but Alex used it, but I don't know, I'll try single ones because it doesn't divide the colours :P

SetProtected(true) means no matter what the grace time is, that asteroid will never be attacked

My bad, it does divide the colours, just done singles.
« Last Edit: May 23, 2012, 07:19:23 PM by Tomfloria »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #40 on: May 23, 2012, 07:46:56 PM »
I don't know why the backdrop is like that, but Alex used it, but I don't know, I'll try single ones because it doesn't divide the colours :P

SetProtected(true) means no matter what the grace time is, that asteroid will never be attacked

My bad, it does divide the colours, just done singles.

SetProtected doesn't exist on PC.
Hmm.  How important is that command?  Does the level not work properly without it?

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #41 on: May 23, 2012, 08:04:11 PM »
It's just a quick way of restricting the seedlings from attacking a certain asteroid, it's not needed at all really, you could just change GraceTime's Manually throughout the level and if you wanted seedlings to attack places you could pre-define it.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #42 on: May 23, 2012, 08:40:35 PM »
Cool.  :>  In that case I'd suggest to remove that command entirely, or at least only run it if IsThisiOS() returns true.  That will make it work on PC too. :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #43 on: May 23, 2012, 11:42:51 PM »
Well i'm just focusing on iPad levels till it's done, then i'll go through it all and change stuff, because I might need to change the storyline, which if thats the case, I'd keep it iPad only, but then make custom random levels for iPad and PC compatible. (I have a few corkers I don't think anyones done before, which will twist the way this games played ;), if it's not been done :D )

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #44 on: May 24, 2012, 07:56:21 PM »
Fair dos :>


Forum is quiet today..  meh.. need codes..

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Common coding tasks
« Reply #45 on: May 25, 2012, 01:24:57 AM »
It is quiet haha, I havnt touched my code since tues, waiting for the special Friday tomorrow :p

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Common coding tasks
« Reply #46 on: May 26, 2012, 08:34:24 PM »
Updated the initial post today.