• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jblevins1991

Array question.

9 posts in this topic

if i have an array called [b]int level[99][/b] and i use the following code [b]++level[99] [/b]does that increment the array's element.

Example say we are at level 3 in our game meaning the level array would be at array[2] for our exp til next level, if i were to level up and use ++level would it be at level[[3]?
0

Share this post


Link to post
Share on other sites
If you have an array of 99 element then level[99] refers to the 100th element, so referencing it is not even allowed. In short, you cannot increment the value of the 100:th element of an array containing only 99 elements.
0

Share this post


Link to post
Share on other sites
What do you mean? An array contains a sequence of elements, but there is no such thing as a current or a next element of an array. From your first post, why are you using an array and not just use a single value to keep track of the level? You do you need an array to keep track of which level you are at when a single value seems to be enough, unless you can be at multiple levels at the same time.
0

Share this post


Link to post
Share on other sites
sorry, i got confused. the array holds the exp amount needed to level up (see below)

int exp;
int exptilnextlevel[99];

if(exp>=exptilnextlevel[99])
{
++level;
}

would this work?
0

Share this post


Link to post
Share on other sites
No, you're still trying to use the 100th element of a 99 long array.
0

Share this post


Link to post
Share on other sites
No. You have an array with 99 element, and the index 99 refers to the 100th element. It is outside the array, so it's not a valid array element.

But ignoring that; yes, the logic is otherwise OK, as long as you index the array properly. You probably want this instead though:
[source]
if(exp>=exptilnextlevel[level])
{
++level;
}
[/source]
0

Share this post


Link to post
Share on other sites
Of course you probably want a bounds check so:

[code]if(level < 99 && exp >= exptilnextlevel[level])
{
++level;
}[/code]
1

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1329522031' post='4914054']
No. You have an array with 99 element, and the index 99 refers to the 100th element. It is outside the array, so it's not a valid array element.

But ignoring that; yes, the logic is otherwise OK, as long as you index the array properly. You probably want this instead though:
[source]
if(exp>=exptilnextlevel[level])
{
++level;
}
[/source]
[/quote]

To slam home the point, you might should check you're not outside the bounds of the array 1st
[source]
// if you're below level 98, then you're good to go
// if you're at level 98, the array only goes up to exptilnextlevel[98], so don't increase the level any more
if (level < 98) {
if(exp>=exptilnextlevel[level])
{
++level;
}
}
[/source]

(Edit Beaten)
0

Share this post


Link to post
Share on other sites
Counting in array references starts from 0, not 1 (as others have said).
That means that level 1 will be array[0], level 80 will be array[79], and level 100 will be array[99].
This is called zero-based indexing.

If I may suggest, you may want to calculate your player levels using a math function.
It seems to me that your players may be able to level up an arbitrary number of times, making it
impossible to pre-define the experience requirements for all levels. (You can define a specific
subset of levels, but that's out of the scope of this discussion).

You can use a site like [url="http://go.hrw.com/math/midma/gradecontent/manipulatives/GraphCalc/graphCalc.html"]this[/url] to visualize your level curve.

[code]
int CalcExpToLevelUp( int level )
{
// y = x^2
// Where y is your xp to level and x is your current level
return level*level;
}

int Level = 0;
int Exp = 0;
int ExpToLevel = 0;

bool Player_Update()
{
...

// Can we level up?
if( Exp >= ExpToLevel )
{
Exp = 0;
++Level;
ExpToLevel = CalcExpToLevel( Level );
}

...
}
[/code]

This may not necessarily be the best or fastest method, but it is flexible.
Keep in mind this is pseudo-code, and not compiled or tested. It is meant
only as a conceptual reference.

I hope this all makes sense, it's been a long night and I'm pretty tired.
I'm sure if there's something I was fuzzy on someone will correct me.
Best of luck!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0