Author Topic: Level design/ Code questions from a beginner  (Read 16117 times)

0 Members and 1 Guest are viewing this topic.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #15 on: April 05, 2010, 12:46:30 AM »
Argh! thank you for getting it to load! i wonder why it mattered that certain asteroids were too far away. its going to be expanded in all directions so im not sure how the spacing works then. thanks again. i think ill leave it now till tomorrow.


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Level design/ Code questions from a beginner
« Reply #16 on: April 05, 2010, 07:53:55 AM »
No worries.  Let us know how you get on :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Level design/ Code questions from a beginner
« Reply #17 on: April 05, 2010, 11:17:52 AM »
this is the whole thing so far. it feels kinda naked, revealing ALL the code, but it's certainly nothing special. some of the globals are pulled directly from one of your maps without me really knowing what it means!  :)

Don't worry about copying my globals.  I copied mine from someone else's map too when I was learning!  :>  Totally allowed.

Also I noticed I missed out this question:

Quote
So - in light of this, in order to make my eventual finished map more interesting, i wanted about 2 or 3 different enemies. this will no doubt have an impact on the coding of the win condition.
erm... any help with that one?

Well you need to define in your own words what the condition of winning should be.
So for example, in my own words, the win/lose conditions at the moment are:

  • If Empire 2 doesn't own any asteroids, the Player wins.
  • If the Player doesn't own any asteroids, the Player loses.


So basically figure out what you would prefer it to be.  Here's my suggestion:

  • If the player owns all the asteroids, the player wins.
  • If the player owns 0 asteroids, the player loses.


So now we simply convert this to code:


Code: [Select]
If GetEmpire(1):GetNumOwnedAsteroids() == 99999 then
Quit(true)
end

If GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Quit(false)
end

Just change 99999 to however many asteroids are in your level.  You can also add Pause() and MessageBox() commands to taste.  :>
« Last Edit: April 05, 2010, 11:22:42 AM by annikk.exe »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 13
  • Posts: 1,035
Re: Level design/ Code questions from a beginner
« Reply #18 on: April 06, 2010, 09:59:49 AM »
Many thanks to annikk.exe and njursten for helping out here!

I've had a look but couldn't tell; is there anything unanswered that I can help with?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Level design/ Code questions from a beginner
« Reply #19 on: April 06, 2010, 10:07:59 AM »
Think we've covered everything so far Alex.. :>  Just waiting to hear how AWS is doing with it.  Hopefully my huge amount of words hasn't scared him off.. :P

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #20 on: April 06, 2010, 11:01:22 PM »
:) nope. no scaring away i assure you. far from it. im extremely grateful this is such a friendly place and peoples quesitons, not just mine by any means, aren't shot down for being a noob, or whatever.

ive been taking in some sunshine since i last posted because its been getting up to the high 80's F/30C so i thought i should get some much needed vitamin d.
BUT - after going over the lovely sin wave graph and the associated code to make the background change colour, i plugged in the first half of it (the stuff before the graph, and it all worked perfectly. i was so pleased that it didnt require umpteen number of reloads, change one number, error, quit, edit, reload, etc. it was quite nice to see it work first time for a change.

so..after watching my creation wave between several colours for a few minutes, i went on the next bit about setting the colour variable to sin(time), the bit after the graph..
the
y = Sin(X)

..becomes..

bcolour = Sin(time)

bit.
i put that in with the previous code and instead, while the level loaded ok, the background just stayed white. so, im not sure how the second part of your instructions are meant to tie in with the first half, but the first bit works and the second, as i did it, didn't. i thought that maybe some of the prior code needed to be removed and the above code put in somethings place.
but thats ok for now. im just pleased ive got this far. im going to have a play with setting all the RGB values, not just one, with the code and see how that plays out.

i will say though that im going to have more Q's quite soon so.. be warned!  :-\

thanks once again to one and all.

ps- i did find the ~ key for the error log. its useful :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Level design/ Code questions from a beginner
« Reply #21 on: April 07, 2010, 07:59:28 AM »
y = Sin(X)

..becomes..

bcolour = Sin(time)

It should actually be bcolour = math.sin(time)  :>


edit - just spent some time figuring out what it is you might have done.
I think what has probably happened is you have placed this additional code outwith the bounds of the While GameRunning() do loop.  So it's not being run on each game cycle - in theory it will run when the While loop ends, which can only happen when the game is no longer running... so basically code placed below the end of a While GameRunning() do loop will never run.

It's also possible that you are inadvertantly overwriting the value of a variable or something like that.  If you can't get it to work, post your function LevelLogic() up, and I'll have a look :>
« Last Edit: April 07, 2010, 08:15:05 AM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #22 on: April 09, 2010, 08:04:36 PM »
:)
lol
im very happy!

i did this code, erm, kind of, by myself. and it gives the effect i want. of course, if i could tweak it to my preferred level of absolute perfection, i would do so, but for now, considering it's taken me a bloody long time, and lots of questioning to get this far, im really very pleased with it. heres the code that gives a seemingly random background colour wave. it changes with enough variation over time to satisfy me for now. i think it's a bit quick still, and is in need of more subtlety (less garishness), but thats for the near future.

heres the code...

while GameRunning() do

   rtime = GetGameTime()    -- setting the variable 'time' to whatever the game time is
   rtime = rtime / 12     -- taking that 'time' variable and dividing it by n.  divide slows down. multiply speeds up.
   gtime = GetGameTime()
   gtime = gtime / 6
   btime = GetGameTime()
   btime = btime / 24


   rcolour = math.sin(rtime) -- setting the variable 'rcolour' to wave up and down. like this the range is now -1 to 1. 1 being the peak of the wave and -1 being the trough. with the horizontal axis as 'time', in this case the 'time' variable.
   rcolour = rcolour * 195  -- setting the range of 'rcolour' from 0 to 255. in this case the 'r' referring to 'red'. do the same with 'g' and 'b'
   gcolour = math.sin(gtime)
   gcolour = gcolour * 235
   bcolour = math.sin(btime)
   bcolour = bcolour * 165

   --rcolour = math.sin(rtime)
   --gcolour = math.sin(gtime)
   --bcolour = math.sin(btime)


   SetBackdropColour(rcolour,gcolour,bcolour)

   coroutine.yield()
   end   

ignore the comments, thats just for me, trying to make sense of it all! but as you can see, ive commented out that 'y = math.sin(time)' stuff, as that made it fade immediately to black, and nothing else. however, with it removed, it does what i wanted so there you go! :)

ofcourse, i fully expect that a constantly changing background isnt for everyone, or even anyone!, but i wanted to see what could be done with it, and im learning exactly that, in its simplest form.

if i could, i would like to able to have it be more 'random' with the colour range, because as you can see, i have to set the ranges of the wave in stone. a varying variable like that might do more of what i would ideally want.

so...i thought i would post my latest, and happiest, discoveries!

AWS

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Level design/ Code questions from a beginner
« Reply #23 on: April 09, 2010, 11:54:58 PM »
Awesome dude :>  Thanks for letting us know !  Really cool to see people making new stuff :>

Regarding the commented out bit.... at that point you already have your rcolour, gcolour and bcolour variables ready to plug into the SetBackdropColour... if you try to math.sin them again you will end up with a value between 1 and -1 again.  So basically the colour will have been 0,0,0 which is black... or at most, 1,1,1 which is still basically black :P


Remember:

math.sin(ANY NUMBER, EVEN A HUGE ONE) = a value between 1 and -1.


May I try out your code? :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #24 on: April 10, 2010, 03:06:06 PM »
Awesome dude :>  Thanks for letting us know !  Really cool to see people making new stuff :>



May I try out your code? :>

of course...ive taken enough from yours that i think its only fair! ::)
(i was going to ask your permission to use your long AI coding on my map to see how it works?!)


EDIT - code now works properly.-thanks. so, first ever level mk.1 is now complete!!
mk.2 will be 'with additions' (ie, more roids and some more globals code for less randomness!) :)
« Last Edit: April 10, 2010, 03:45:01 PM by AWS »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #25 on: April 10, 2010, 06:58:49 PM »
 ::)

right...
i have some Q's that id be interested in hearing the answer to. and, somewhat crucially, how it would be applied in an example.

1-Globals.Mines.SpeedPower (float) - this sets the speed power of a mine, it says, but what is 'speed power' as opposed to 'speed' or 'explosion power'? and would it be a value btween 0 and 1 only?
2-what is a 'float' value? and what is an 'int' value?
3-ok, i want to have it so the enemy maxes out trees, etc on the roid theyre on, before exapnding out. but without lots of complicated coding to check lots of other variables (ahem!). is there a simple way to just say, '80% of the time, the enemy will max out current asteroid before expanding'? (also having that expanding code too).** this one isnt essential to me for now but it would be nice to have the code available for later use.**

thats all for now... :)
thanks.

AWS

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #26 on: April 10, 2010, 09:31:20 PM »
well...after much frustrating nonsense and testing..i still cant decide what my map is actually like!! but i reckon its near completion so soon enough there will be another map gracing this fine forum for anyone daring enough to take it on.

in the meantime i have two questions..

1-is it possible to 'sticky' a particular thread on the forums, so that i can access it quickly without having to search through and find it each time? like, some sort of dashboard in ones profile where you can store a few threads for continued personal reference. that would be a nice feature if it isnt one??
- moderators, could it be added?

2-how do i upload a map here?
before i do that though,  if anyone is interested in testing my map  ???, pointing out any major issues, please let me know, on here or in a pm. id be really happy to release a map that people will enjoy so any testers will be welcome. let me know folks...
but, until someone can point out how to upload the single .lua file, all i can think of is to copy and paste all my code, which isnt good!

?

AWS

 :D

njursten

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
Re: Level design/ Code questions from a beginner
« Reply #27 on: April 11, 2010, 12:29:08 PM »
When writing a post there is link called "Additional Options...". Press that one and a new field will appear where you can select a file.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 274
Re: Level design/ Code questions from a beginner
« Reply #28 on: April 11, 2010, 07:19:57 PM »
When writing a post there is link called "Additional Options...". Press that one and a new field will appear where you can select a file.

thank you.

Mihhaelo

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 67
Re: Level design/ Code questions from a beginner
« Reply #29 on: April 11, 2010, 11:15:58 PM »
Quote
Argh! thank you for getting it to load! i wonder why it mattered that certain asteroids were too far away. its going to be expanded in all directions so im not sure how the spacing works then. thanks again. i think ill leave it now till tomorrow.

When the game opens up a file, it sets up the map. When it does this it scans through all the planets to make sure they are "connected" to the other planets. If the maximum send-distance, maxasteroidneighbour distance, etc is too low in the globals and it is unable to connected a planet to at least one other planet it will refuse to load. You can get around this by changing the values in globals or by manually setting SendDistance values so that every planet is within range of each other. As long as planets are connected, you can go upto silly coordinates like, -100000,-100000  :D