Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / keeping score throughout the game

Author
Message
kirtn14
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 2nd Apr 2013 17:08
i was just wondering how i would kep the score variable throughout the game because i have used new.agc files for each level but want the score to be cept constant throughout them all. how is this done please?

kirtnicholls
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Apr 2013 17:16
All you need to do is use a global. I'm sure you have a main source file, where all your extra code is 'included' - so in there, you could have a score variable as a global:

Global SCORE = 0

Then just reset it at the game start, and it'll be a global variable, accessible from anywhere.

You could have this in an included source file as well, just as long as it's called.
You can also globalize your arrays too, like:

Global Dim SCORETABLE[10]

I got a fever, and the only prescription, is more memes.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Apr 2013 18:08
kirtn14:
Unless you are doing something like a party game with different gameplay on each level, you should consider programming a function to load levels and using a single main loop with a single sync() command. It's both good programming practice and a great learning experience.

Van:
I believe arrays are always global like in DBP. I DIM most of my arrays in various setup functions.


Demo 3 is out now!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2013 21:03
Quote: "Global Dim SCORETABLE[10]"

Like Digital Awakening says, this is unnecessary, arrays are global by default.

Quote: "Dim SCORETABLE[10]"

This does the same thing.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Apr 2013 21:59
Hehe, force of habit - been doing that in included subs, but really it would only make a difference inside a function.

I got a fever, and the only prescription, is more memes.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Apr 2013 22:12
Quote: "Hehe, force of habit - been doing that in included subs, but really it would only make a difference inside a function."


Actually no. That's what I meant with my post. You never have to declare arrays as global as they are always global. No matter where you dim them.


Demo 3 is out now!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2013 22:25
/\ What he said. lol

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Apr 2013 22:53
Hmmmmm, not sure I like that - any array you create in a function should really be limited to that function unless it's globalised, I'm sure that's how DBPro works and other languages. Not too keen on array housekeeping, I'd rather just dim an array inside a function if I need to, and not have it taking up memory afterwards.

I got a fever, and the only prescription, is more memes.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2013 22:59
Nope. In DBP, all arrays are global. I use this feature to initialise sub systems in my engine. Each include file is fully self contained, you can an initialisation function which creates all global variables and arrays, which are then accessible everywhere.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Apr 2013 23:04
Strange, I'm sure I had to do that in the past.

Ohh well, live and learn!

I got a fever, and the only prescription, is more memes.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2013 23:40
Even the greatest still learn daily.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]

Login to post a reply

Server time is: 2024-11-24 12:03:14
Your offset time is: 2024-11-24 12:03:14