Collected items question..plz.. :)

Talk about making games.

Collected items question..plz.. :)

Postby Camper1995 » Fri Jul 03, 2009 3:20 pm

please read this all so you can understand my question...
Hello people. I am making new game called SpongeBob and its almost finished, but, I have one problem.
Its a platform game and you are collectig food and when you collect it you have + 10 points..classic.
But, there is option save and load game. When I save and then exit the game and again start it and load it, there is food that I have collected, sou you can
make unlimited highscore.
So my question is: how to save collected food, so when you load game, that food what you had collect is invisible,...transp=1; :D

you know, I was trying to make this this way: Make on item variable fs (like FoodSave)
so, when create...fs=1
when destroy fs=0
when destroy saveVars....
and when create load vars..
and when create if fs==1..transp=0
if fs==0 ... transp=1;

But this doesnt work.. why?

Plz help me.

Here is screenshot from my new game:
image 1.jpg


Thanks,
Camper.
:)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Collected items question..plz.. :)

Postby skydereign » Fri Jul 03, 2009 8:40 pm

Well as the creator, you have several privileges. If I understand you, the levels are preset, so more food does not spawn on the field, you have the entire level layed out. If so, you could create an array, signifying the food clones.
Code: Select all
int foodSwitch[ActorCount("food")];

Since you are using load and save, I think you would need to create a variable within, so you might just put the ActorCount number, not ActorCount. A bit of a hack, but it would work, I think.

Then on collision with player.
Code: Select all
foodSwitch[cloneindex]=1;


Then you can load save that.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Collected items question..plz.. :)

Postby Camper1995 » Fri Jul 03, 2009 9:01 pm

Well, thanks for helping me but I dont understand you too much.
Look, I have for example 500 colnes of food
and I wanna do, when I pick up it, destroy it and save variable that that food was destroyer.
So when I load game, all destroyed food are invisible (transp...)
and all not destroyed food are normal on the map. Do you understand me now? :D

And all 4 levels are in one game so there is not loading between each levels.

Thnx, Camper. :)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Collected items question..plz.. :)

Postby DST » Fri Jul 03, 2009 11:20 pm

Skydereign just left the last part off (perhaps for you to figure out, in which case i've ruined it)
foodswitch[500]; (make it using the variables tab)

collision>player>
foodswitch[cloneindex]=1;

next load,
food>createactor>
transp=foodswitch[cloneindex];
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: Collected items question..plz.. :)

Postby Camper1995 » Sat Jul 04, 2009 10:06 am

ok, so what I need to do.

Create actor food> Script editor>foodswitch[630];

then when collide with player> Destroy actor event actor? and foodswitch[cloneindex]=1;

create actor>transp=foodswitch[cloneindex];

is this right? :D
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Collected items question..plz.. :)

Postby DST » Sat Jul 04, 2009 4:58 pm

Camper1995 wrote:ok, so what I need to do.

Create actor food> Script editor>foodswitch[630];



No, use your variables tab to create a variable called foodswitch, make it an array, size 630, save in your save group.


In normal scripting you'd use
Code: Select all
 int foodswitch[Actorcount("food")];
This will create an array the right size every time. If you make it using the variables tab, you'll have to manually change it every time you add more food to the game. If you want to do it this way instead, you'll have to cue it from a specific trigger - not in global startup. Because you need to make sure ge has actually created all the clones to count first. Just add a keydown event so you can do that whenever you need, and then save the array.
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: Collected items question..plz.. :)

Postby Zivouhr » Wed May 28, 2014 1:22 am

Thanks for all of the tips offered here about the food items collected by Spongebob for the game created by Camper, which looks cool by the way, great artwork too.

I gave the codes suggested a try as a beginner to the C Language, but have a question or two regarding the implementation of the scripting. While I can save and load the clone.0 actor, clones.1, 2, 3 etc won't save or load from my set up. I can successfully save/load textNumbers, like score, player lives, etc, but clones I haven't been able to get working yet and it's the most important part of saving, so an unlocked door will stay unlocked on load, etc.

I tried including a zip file of the basic process I attempted, but it didn't load up here for some reason.
Game includes: 1 player. 1 save key, 1 load key, 500 food items for example that become transparent (1.000) when the player contacts them in a test file. (It's actually less than 500 in the actual game, but just want to keep in line with this thread for the consistency).

Question 1: Are these codes in the right locations?
-------------
foodswitch variable created inside the script editor? Yes. Set to array, 500 number set, for 500 food items. Integer Global. Save group is "savegame" ( or savegame ).
-------------
player/events/collision with food/repeat on/script editor:
foodswitch[cloneindex]=1;
-------------
food/events/create actor/script editor:
transp=foodswitch[cloneindex];
-------------
Where does this code go? I tried putting it into a few script editor locations like above, but it brings up an error message and prevents it. I'm guessing it's not needed if a variable was already created though, true?
int foodSwitch[ActorCount("food")];
-------------
player/keydown/ s / script editor //s keydown means Save when pressing "s" on the keyboard
foodswitch[cloneindex]=transp;
saveVars("savegame.gdt", "savegame"); //variable being the second item in quotes, "savegame".

-------------
player/keydown/ l / script editor //the letter "L" meaning load game on the keyboard. "L" meaning "l".
loadVars("savegame.gdt", "savegame");
transp=foodswitch{cloneindex}; // I tried entering numbers in the cloneindex area, but it rejects the load code.

-------------

Any suggestions are greatly appreciated, as it will allow the player to save and load their progress in a giant adventure game created in Game Editor, 100MB+. Thanks! 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Collected items question..plz.. :)

Postby lcl » Wed May 28, 2014 9:40 pm

Hi Zivouhr! Welcome to the forum! :)

Now, here's what's wrong with your code, and how to fix it.

First error is here:
player/events/collision with food/repeat on/script editor:
Code: Select all
foodswitch[cloneindex]=1;

Your code uses player's cloneindex, which is always 0. So, instead of setting the foodswitch numbered the same as the food to 1, it always sets the foodswitch[0] to 1.
This is easy to fix. Just use collide.cloneindex instead. This way it uses the cloneindex of the actor the player actor is colliding with -> the correct food clone.

And this code:
Code: Select all
int foodSwitch[ActorCount("food")];

As you said, you won't need this if you've already created the array.
The point of that code was that it would allow you to have the array always be exactly the size it needs to be, no more no less. But if you used that code, you wouldn't be able to use saveVars and loadVars, you should manage the saving and loading yourself.

Here's the same error as in the first code:
player/keydown/ s / script editor //s keydown means Save when pressing "s" on the keyboard
Code: Select all
foodswitch[cloneindex]=transp;
saveVars("savegame.gdt", "savegame"); //variable being the second item in quotes, "savegame".

This again uses the player actor's cloneindex, which is 0. Instead of that, you'd want to loop through all the clones of the food actor.
Like this:

Code: Select all
int i; //Make a temporary integer for looping
char temp[256]; //Make a temporary string variable for storing a clone's name

for (i = 0; i < 500; i ++) //Loop from 0 to 499
{
    sprintf(temp, "food.%i", i); //Print the clone number i's name to string temp
    foodswitch[i] = getclone(temp)->transp; //Use getclone to get the food.i clone's transp and store it to foodswitch[i]
}

saveVars("savegame.gdt", "savegame");


And finally, you'd have to do this same loop thing when loading.
Just use this instead:
Code: Select all
getclone(temp)->transp = foodswitch[i];


I hope this helps!
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Collected items question..plz.. :)

Postby Zivouhr » Sat May 31, 2014 1:39 am

LCL,

Thanks very much for the fast response! Much appreciated and I will give this info a try tonight if I have time. Your description looks very complete and your expertise is a great asset on this site as your suggestions have helped me in the past, while browsing the forum before signing up.

Will post results hopefully soon. Thanks again! 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Collected items question..plz.. :)

Postby Zivouhr » Sat May 31, 2014 7:38 pm

Thanks again for the work you've done to enter all of that C coding.

After carefully entering the scripts into the appropriate actor events as you suggested above, and adding the necessary variables below, to get the code to accept:
i
temp

It's not saving/loading the visibility of the items collected when I exit the game and return while in game editor or in .exe (game on desktop), as the score does successfully along with the player's position x and y.
The items are still visible as on the first play, instead of loading up transparent (invisible) after they were collected by the player.

So the next few quick questions, if you have time, would be:
---------------
Does the "temp" variable get the array set to "Yes" in the variable Edit window, and if so, saved as 500, or 499 since 0 is counted as 1 within clone.0, and saved too in the save variable? I tried both 500 and 499, but haven't had success yet. Or should it just be left as a blank integer global?

And does the "temp variable need to stay at 256, or can it be set to 500 also? I'm guessing 256 is a random number just to create a temporary file, but don't fully understand the logic of it yet.
int i; //Make a temporary integer for looping
char temp[256]; //Make a temporary string variable for storing a clone's name





Does "i" as the variable (created in script editor), also get saved as an array set to 500?

For loadVars, I get a Warning line 3: Trying convert from 'const * long int' to '* const char', There are some errors but are not fatal. Proceed anyway? Yes, No

First error is here:
player/events/collision with food/repeat on/script editor:

foodswitch[cloneindex]=1; //old code that didn't work.


Your code uses player's cloneindex, which is always 0. So, instead of setting the foodswitch numbered the same as the food to 1, it always sets the foodswitch[0] to 1.
This is easy to fix. Just use collide.cloneindex instead. This way it uses the cloneindex of the actor the player actor is colliding with -> the correct food clone.


Based on your suggestion, I set:

player/events/collision with food/repeat on/script editor:

Code: Select all
  foodswitch[collide.cloneindex]=0;


---------------
Sorry for the trouble. I tried without saving and array for both of the variables i and temp, but still no luck getting the items to load as they were when save was pressed.
With more familiarity with C, I think I would have been able to apply this more efficiently, but as of now, I'm still learning.
Thanks for all of your help, as this will help other beginners trying to save/load items as well. 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Collected items question..plz.. :)

Postby lcl » Sat May 31, 2014 10:26 pm

Hi. Sorry, my instructions seem to have been a little less detailed than they should have been for providing you complete understanding of what you need to do. Here's what's wrong with your implementation of my instructions.

1. You don't need to add any variables via the "Variables" window. My code examples create the variables by using the keywords int and char of C programming language.

This creates an integer variable i:
Code: Select all
int i;

And this here creates an array of characters, a string, with the length of 256 characters. These 256 characters will be stored in the char array elements 0 - 255, this is also how all other arrays work, the highest index you can use is the size given - 1. This may seem illogical, but since the first element you can use is the number 0, the amount of usable elements will be equal to the size you've given to the array. This would be the same thing as it would be to select "String" from the variable adding dialog, and to set it's size to 256. The only difference is that that method would create a global variable, while this code creates just a local variable, because it's executed in a local event.
Code: Select all
char temp[256];


Because these variables are created in a local script event, they are local variables, that only exist in that specific event. I should have explained that to you.

2. This should not be:

player/events/collision with food/repeat on/script editor
Code: Select all
 foodswitch[collide.cloneindex]=0;

But instead:
Code: Select all
  foodswitch[collide.cloneindex]=1;

That is because 1 means full transparency, and 0 means no transparency.

I hope this clears things up for you. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Collected items question..plz.. :)

Postby Zivouhr » Sun Jun 01, 2014 8:30 pm

LCL,

Okay, thanks for describing this in more detail relating to the variables already being defined, thanks to your code. Still being new to C coding, I have been reading up on what different C language scripts, functions and syntax' can do, so I'm starting to understand a little bit more than when I began.

Your explanation is clear and sounds good. Thank you one more time for your efforts, LCL! :D
I will give this a try and will post results when I get a chance.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Collected items question..plz.. :)

Postby Zivouhr » Sun Jun 01, 2014 11:09 pm

lcl wrote:
I hope this clears things up for you. :)


Success!!! I was finally able to get it working thanks to your help, LCL. To see the clones on loading from a new boot up game stay hidden as intended with the save, was a great moment, while working on my first adventure game on Game Editor. Many thanks to you especially, as well as to all of those who posted in this thread, and for Camper for starting the thread with the same question I had.

With the load, I was mistakenly putting loadVars on top of the script editor page, but then thought about how I remember seeing the int (integer create variable command) always near the top of the page. I was thinking that had to also be beneath loadVars in order to work, but instead, put them above it and then as you described, use the same code for loadVars as saveVars, but instead substitute the getclone line which is reversed compared to the save one.

player/key down/ l (letter "L" on the keyboard): (for loading the saved items)

Code: Select all
int i;    // this automatically creates a variable after you start test the game.
char temp[256];    // this variable, should also be above the loadVars command. Below it, and an error will pop up.
loadVars("yoursavedgamehere.gdt", "yoursavedgamevariablehere");
for (i=0; i<500; i++)
{
sprintf(temp,"food.%i", i);
getclone(temp)->transp=foodswitch[i];    // this is reverse order from the save order, more or less it seems.
}


And the rest:

player/events/collision with food/repeat on/script editor:
Code: Select all
foodswitch[collide.cloneindex]=1;
//oops. collide goes here so the player hits the collide clones.
-------------
food/events/create actor/script editor:
Code: Select all
transp=foodswitch[cloneindex];

-------------
player/keydown/ s / script editor //s keydown means Save when pressing "s" on the keyboard

Code: Select all
int i;    // this automatically creates a variable after you start test the game.
char temp[256];    // this variable, should also be above the loadVars command. Below it, and an error will pop up.

for (i=0; i<500; i++)
{
sprintf(temp,"food.%i", i);
foodswitch[i]=getclone(temp)->transp;    // this is reverse order from the load order, more or less it seems.
saveVars("yoursavedgamehere.gdt", "yoursavedgamevariablehere");   

//saveVars on the bottom instead of on top.    //Everything above saveVars will get saved. Beneath it, not saved.



Big relief to get this saving and loading of clones working after many attempts. Thanks again!! 8) :D
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Collected items question..plz.. :)

Postby lcl » Mon Jun 02, 2014 6:20 am

Oh, yes, I forgot to mention that loadVars should be above the for loop, while saveVars should be after it.

It's quite logical of course, thinking about the fact that you first have to load the values from the file, before you can use them to set the transparency of the actors, and also you first have to set the variables equal to the actors' transparency to get it to save the correct values. But should've remembered to point that out as well. :)

But there's one more thing I'd recommend you to consider. You are currently just making actors transparent when you don't want to have them appear in the game. But there's a downside to doing that:

Setting transparency to full 1 doesn't make an actor completely invisible. At some cases you can see like a "ghost" of the actor, and that's not good. Changing transparency is meant for making actors transparent, not invisible.

Instead of using transparency, I'd suggest you to use the VisibilityState() command. Upon collision with a foodactor, you can use VisibilityState to set the collide actor's visibility state to disabled. You can still use the variable to save the number 1 for indicating that the actor should be invisible. So that when you load the variables, you can instead of having this:
Code: Select all
getclone(temp)->transp = foodswitch[i];

Have this:
Code: Select all
if (foodswitch[i] == 1)
{
    VisibilityState(getclone(temp)->clonename, DISABLE); //This code sets the visibility state diaabled for the actors who have their corresponding foodswitch variable saved as 1.
}

Of course, now you may think that there's a problem with saving the variables, because now we can't anymore set the variables equal to the actors' transparency. But there's a catch. I didn't think clearly when I told you to have a loop for saving the variables. There's no need to set the variables anymore, because you have already set them to 1 upon player's collision with the foodactors. So now you can replace your whole saving code with just the saveVars call. :)

This may sound like a waste of time when you already have your system working, but it's good to get rid of the habit of using transparency for making actors invisible because it's not working 100% as you'd like it to. And when there's a perfect command for making actors invisible, why not use that? :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Collected items question..plz.. :)

Postby Zivouhr » Tue Jun 03, 2014 2:06 am

lcl wrote:Of course, now you may think that there's a problem with saving the variables, because now we can't anymore set the variables equal to the actors' transparency. But there's a catch. I didn't think clearly when I told you to have a loop for saving the variables. There's no need to set the variables anymore, because you have already set them to 1 upon player's collision with the foodactors. So now you can replace your whole saving code with just the saveVars call. :)

This may sound like a waste of time when you already have your system working, but it's good to get rid of the habit of using transparency for making actors invisible because it's not working 100% as you'd like it to. And when there's a perfect command for making actors invisible, why not use that? :D


Thanks LCL for the extra details on visibility state. Will definitely consider it. Looking at my game during gameplay and on the game editor screen, my invisible actors are seemingly completely invisible to my eyes; where they can't be collided with anymore, and I see no ghost images of them either> Possibly because I have sky actors and parallax actors behind them. I'm guessing that if nothing was behind them, then maybe they would appear as you suggest.
I'll have to experiment more with it to see if I can spot them.
But I agree, I want them completely invisible so your visibility explanation is much appreciated. Thanks again for all of your help. I know it took you time to go into all of the details and explain everything as thoroughly as you have done, and it has helped out tremendously. 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest