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.

Newcomers DBPro Corner / Saving a type

Author
Message
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 24th Nov 2011 22:55 Edited at: 24th Nov 2011 23:18
So how could I save something like this:



Do I save each little thing individually like write long 1, player.health

Or is there another command that will work?

Also, since my other post seems to be dead, I need help with this.



The enemy(a).hits is to track it, the enemy(a).hitsReq is set to 2, but they still die after one hit with the bullet, is it calculating 2 hits instead of just one? I have the state set back to false but idk whats happening.

-------------------------------------------------------------
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Nov 2011 23:29
Quote: "Do I save each little thing individually like write long 1, player.health"

Yes, or you can save the data in text format also.
However there is another option if your type is in an array...

Quote: "but they still die after one hit with the bullet"

Are you remembering to reset the 'hits' value to zero when you set up your enemy initially?
Are true and false defined? What to?

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 25th Nov 2011 00:33
Quote: "However there is another option if your type is in an array..."


What is it? This was just an example of my code, I have array's in entity too.

Quote: "Are you remembering to reset the 'hits' value to zero when you set up your enemy initially?
Are true and false defined? What to?"


Yes. Yes. Im not sure. Here's the full code, maybe this will clear it up.



-------------------------------------------------------------
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 25th Nov 2011 05:54
A third question, quoted from the old post.

Quote: "Also, fixed the respawning. (Thanks to being a fast learner and using what you taught me with the avbl thing.)

But for some reason it messes up the collision, not sure why.



Also I did change the moving/collision a little bit, but that was just a check to make sure they don't collide with enemies that are dead.
So if the error has something to do with the changes tell me.



Oh yeah, another important thing to mention is that this only happens on the X way, collision is fine on the Y."


-------------------------------------------------------------
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Nov 2011 14:35
The alternative is available if you use my plug-ins, in particular the array and datafile plug-ins. I'll post some code for you later tonight.

I'll take a look at your code then too.

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 25th Nov 2011 16:07
You can save arrays using something like this. The routines are array specific. Saving an array passed to a function wouldn’t be a problem. But loading an array passed to a function would require a little more wizardry.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 25th Nov 2011 19:43 Edited at: 25th Nov 2011 19:45
Im not too good with memblocks, is it possible just to do this?



ect?

Also what about my other questions?

-------------------------------------------------------------
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Nov 2011 19:47
The MAKE MEMBLOCK FROM ARRAY is perfectly usable, as long as you do not involve strings. Adding strings to the mix will cause you issues when you reload.

Quote: "freeMemblock
freeFile"

Use my plug-in's FIND FREE MEMBLOCK and FILE FREE FILE (or FIND FREE DATAFILE if you follow my suggestions) - they are far faster than even those simple functions.

What I am going to suggest is using my plug-ins to just write the array to a file directly.

Here's the code I use to test the save/load functionality:


The key lines in the code to save are:
OPEN DATAFILE TO WRITE
SAVE ARRAY TO DATAFILE
CLOSE DATAFILE

The key lines to load are:
OPEN DATAFILE TO READ
LOAD ARRAY FROM DATAFILE
CLOSE DATAFILE

You can save stuff to the datafile both before and after you write your array too. Plus the datafile file access is far faster than DBPro's file access.

You will see some ARRAYPTR commands in there too, but you can just ignore them - they are simply testing the same functionality for array pointers.

Now I'm going to look into the code - I'll post later.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Nov 2011 22:58
Problems with the code:
1. The bullet was only disabled if it destroyed the enemy, not if it hit the enemy.
2. The hit count was increased after the check to see if the enemy should be destroyed, meaning it would die on the third hit, not the second.



WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 26th Nov 2011 00:14
IanM’s, plug-ins are the best way to go.

Quote: " Adding strings to the mix will cause you issues when you reload."


Can you show me were loading strings could go awry. This code seems to load strings in the array just fine.



Thank you.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Nov 2011 00:59
When you convert the array to a memblock, the data held in the array is copied directly into the memblock - the problem is that the data in the array for strings is a pointer to the actual string data, so that what is copied is a pointer, not the string itself.

When you load your memblock back into your program, those pointers are restored, but if your program has been restarted since saving the array data, those pointers could literally point to anything in memory.

The only time they are guaranteed to point back to their original data is if you do not stop your program, you do not create/change/delete any strings, and you load the array back - basically, not likely to happen.

Write one program to save, then write another program to load - you'll see this in action.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 26th Nov 2011 02:31
Thanks that helps alot, but the collision is still messed up and I don't see why.

-------------------------------------------------------------
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 26th Nov 2011 02:34
I see what you mean now. With strings I'm getting the generic; Program has stopped working. Without strings the programs run fine.

Thanks
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Nov 2011 12:45
Quote: "but the collision is still messed up"

Post your latest code, along with a description of what 'messed up' means

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 26th Nov 2011 19:39 Edited at: 26th Nov 2011 20:30


When the enemies collide on the X way, they go into each other. This seems to have started after making the bullet system, But I'm not sure why. Collision is fine on the Y way.

EDIT: I have another question, I have this:



But what I want it to do is if currbullet (I should probably change the name, its what I use to keep track of how many bullets are left) equals more than a row limit (6 per row) then advance to the next row and keep pasting. But I'm not exactly sure how to do this.

-------------------------------------------------------------
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 30th Nov 2011 06:57
Ah, and my post gets ditched once again.

-------------------------------------------------------------
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Dec 2011 20:53
Patience. I have a real-world job too - they pay me more than you do!

Perhaps you'd like to start by explaining the rules behind the enemy movement so that I can understand the difference between what you coded and what you should have coded.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 4th Dec 2011 08:16
Well, it's a simple AI, due to the fact the enemies are zombies lol. So not much to it. I probably just messed something up.

The first part checks if they're colliding with each other and moves them if they aren't touching. And the second part, well its that moving part lol.

-------------------------------------------------------------
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Dec 2011 14:47
Well I suspect that what's happening is that your code is letting the enemy move into contact (you are not checking for contact after moving, only before), and once they are in contact, the code to move them apart is actually moving them both in the same way.

Anyway, what I meant by 'rules', was something like the following:
- Move down.
- If in contact with another enemy move back up, then move left.
- If in contact with another enemy move back up, then move right.
- If in contact with another enemy move back up.
- Vertical movement is in steps of 10 pixels.
- Horizontal movement is in steps of 5 pixels.

Login to post a reply

Server time is: 2024-05-20 04:21:46
Your offset time is: 2024-05-20 04:21:46