Thoughts about data control

You must understand the Game Editor concepts, before post here.

Re: Thoughts about data control

Postby Fuzzy » Fri Jul 02, 2010 10:17 am

Nice functions bee.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Mon Jul 26, 2010 5:23 pm

Function to handle stuff on inventory...it can be items, weapons, armors, etc...
Code: Select all
//Here's the custom functions to operate Item and Weapon made by Bee-Ant
const int MAX_SLOT=99;              //is the max slot
char stuff_name[MAX_SLOT+1][32];
int stuff_atr[MAX_SLOT+1][2];       //[index][0] is the type, while [index][1] is the amount
//The type as follow :
int item=0;
int weapon=1;

void delete_stuff(char*A,int type) //A is the stuff name
{
    int i,index;
    for(i=0;i<MAX_SLOT;i++) //search the stuff index
    {
        if(!strcmp(stuff_name[i],A)&&stuff_atr[i][0]==type)
        {
            index=i;i=MAX_SLOT; //gotcha
        }
    }
    strcpy(stuff_name[index],"");stuff_atr[index][0]=0;stuff_atr[index][1]=0; //delete the stuff
    for(i=index;i<MAX_SLOT;i++) //re-sort the stuff list
    {
        strcpy(stuff_name[i],stuff_name[i+1]);
        stuff_atr[i][0]=stuff_atr[i+1][0];
        stuff_atr[i][1]=stuff_atr[i+1][1];
    }
}
void use_stuff(char*A,int type,int amount) //A is the stuff name
{
    int i,index;
    for(i=0;i<MAX_SLOT;i++) //search the stuff index
    {
        if(!strcmp(stuff_name[i],A)&&stuff_atr[i][0]==type)
        {
            index=i;i=MAX_SLOT; //gotcha
        }
    }
    if(stuff_atr[index][1]>amount)
    {
        stuff_atr[index][1]-=amount; //use if current amount higher than the requested amount
    }
    if(stuff_atr[index][1]==amount)
    {
        delete_stuff(A,type); //delete if the current amount equal with the requested amount
    }
    if(stuff_atr[index][1]<amount)
    {
        //you can add some alert that the requested amount higher than the current amount here
    }
}
void add_stuff(char*A,int type,int amount) //A is the stuff name
{
    int i,index=MAX_SLOT+1;
    for(i=0;i<MAX_SLOT;i++) //search the last/empty stuff index
    {
        if(!strcmp(stuff_name[i],""))
        {
            index=i;i=MAX_SLOT; //gotcha
        }
    }
    if(index<MAX_SLOT+1) //if the slot isn't full yet, add the item
    {
        strcpy(stuff_name[index],A);
        stuff_atr[index][0]=type;
        stuff_atr[index][1]=amount;
    }
    if(index==MAX_SLOT+1) //if the slot is already full
    {
        //you can add some alert here
    }
}

Usage :
Code: Select all
//function("stuff name",stuff type, stuff amount);

add_stuff("antidote",item,1); //1 is the amount you want to add
use_stuff("antidote",item,1); //1 is the amount you want to use
delete_stuff("antidote",item);

add_stuff("sword",weapon,2); //2 is the amount you want to add
use_stuff("sword",weapon,2); //2 is the amount you want to use
delete_stuff("sword",weapon);

System :
- You can have item and weapon get the same name
- You can add more type by adding more type variables
- You can extend your slot by changing the MAX_SLOT value
- All the stuffs stored in the same array to simplify the operation
- All the stuffs have their own type to avoid missoperation
- To neutralize typo such as "anTidotE", use the letter case function here :
viewtopic.php?f=5&t=6854&start=60#p59790
So in the usage, you can type something like this :
Code: Select all
add_stuff(ToLower("AnTiDote"),item,1);

It will be converted to "antidote", so no worries on typo :D

Hope helps :D
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby zxcvbnm » Mon Aug 23, 2010 1:33 am

Hello sirs , nice to meet all of you. I happen to read the post here and while many are very advanced beyond my coding ability, I find this articule intoxicating. My data control is not as advanced but effective. I will pose a simple example I have in mind.

In a space invaders type game I use 2 filled regions that I place above and below the view. Then on the collision command any actor , usaully bullets, I put destroy actor collide actor.
Now what this does is free memory by destroying any actor that has exited the screen and is no longer useful.
That is a simple example of how to save memory space by deleting charactors not in use. Thank you for your time in reading this and I hope to add many more posts of wisdom to your data control articule.
zxcvbnm
 
Posts: 249
Joined: Sun Aug 22, 2010 7:57 pm
Score: 10 Give a positive score

Re: Thoughts about data control

Postby DST » Mon Aug 23, 2010 3:29 am

Use Out of Vision>Destroy Actor for destroying offscreen actors. It's in the actor events list.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby DilloDude » Mon Aug 23, 2010 3:43 am

Or you can check the actor's y-coordinate.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: Thoughts about data control

Postby zxcvbnm » Mon Aug 23, 2010 12:25 pm

Thank you kind sirs for showing me a more effective way of data control. Now onward to more coding matters. Lets say I have made a mario type game with the variable being "mjump" . As usual many people will give the value of mjump=1; in the physical reponse setion. Let say the programmer wanted a platform where the player
would do a double or triple jump. Normal on pure instint the programmer would make another variable and set the value at 2 or 3 depending how many times the player would be alotted to press the button.
Now my method would not to declare another variable. There is no need because you can just change the value of " mjump" to 2 or 3 for the specific platform you want the player to be able to double or triple jump. This saves you precious memory which could be used in another part of your game. This concludes today's lesson and I thank you all for taking out the time to read this.
Check out Momo AlienStarcatcher , featured in apples new and noteworthy and has 5 star reviews!!!
http://itunes.apple.com/us/app/momo-ali ... 61779?mt=8
zxcvbnm
 
Posts: 249
Joined: Sun Aug 22, 2010 7:57 pm
Score: 10 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Tue Aug 24, 2010 1:18 am

zxcvbnm wrote:There is no need because you can just change the value of " mjump" to 2 or 3 for the specific platform you want the player to be able to double or triple jump. This saves you precious memory which could be used in another part of your game.

Make the work more effective yes, save precious memory not really...
Integer only sized 2 bytes.
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Sun Aug 29, 2010 1:05 pm

Bee says that sun java 6 with Ubuntu prevents posting on GE. I dont know how hes controlling his data, but it works for me. :P
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Mon Aug 30, 2010 3:13 am

Fuzzy wrote:Bee says that sun java 6 with Ubuntu prevents posting on GE. I dont know how hes controlling his data, but it works for me. :P

Darn you...at least I could control anything faster than you :P
I didn't say it prevents me from posting, it just made my firefox a little messed up...
Anyway, it was on 9.10
Haven't tried it on 10.04 :mrgreen:
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby NightOfHorror » Thu Feb 10, 2011 1:37 am

as embarassing as this what makes up strings
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1825
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: Thoughts about data control

Postby needaname » Sat Feb 12, 2011 11:04 am

a string is an array of char so characters
needaname
 
Posts: 69
Joined: Tue Nov 09, 2010 2:07 am
Score: 4 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sun Feb 13, 2011 2:48 pm

needaname wrote:a string is an array of char so characters

Actually string is an array of integer. The difference is just it's stored in the characters ASCII form, and you can't do math operation on it.
So,
Code: Select all
char str[32]="needaname";

and
Code: Select all
int str[32]={110,101,101,100,97,110,97,109,101};

are ALMOST the same.
110 is the ASCII code for "n", 101 for "e", etc...
To convert the char to int, you can do this:
Code: Select all
intvar=(int)str[index];

And to convert int to char, you can do this:
Code: Select all
sprintf(str,"%s",&intvar);

:D
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby needaname » Mon Feb 14, 2011 10:34 am

well doesnt ge use chars as the basis of the string? neway they are pretty much the same thing so since char is the special case of an int saying they are chars is being more specific right? you can do math with chars if you wanted but that woudnt make much sense. i think the opposite applies here as well.
needaname
 
Posts: 69
Joined: Tue Nov 09, 2010 2:07 am
Score: 4 Give a positive score

Re: Thoughts about data control

Postby Game A Gogo » Mon Feb 14, 2011 11:00 am

It's only logical doing math with an unsigned char. especially if it's a byte taken from a file.
but some things with char often gives you random error you can avoid by having it an int...
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3465
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Thoughts about data control

Postby NightOfHorror » Tue Feb 15, 2011 2:42 am

What is an array?
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1825
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

PreviousNext

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron