Help with savefile function i created?

Blitz3D Forums/Blitz3D Beginners Area/Help with savefile function i created?

Guy Fawkes(Posted 2012) [#1]
Hi all. I have decided to rewrite my save file and load file code to a new function, because for some reason, it wasnt saving imported objects. it was only saving generated objects. I need it to save ALL objects on the screen... Not just 1 object like it's been doing. And u CANT say "O, u didnt work on it", because I did. if u do say it, i will ignore u. :)



Here's the code:







Any help is greatly appreciated! :)



Thanks! :)

Last edited 2012


Drak(Posted 2012) [#2]
You need more information.

What do you want it to do?

What doesn't it do right now?

What is wrong or incorrect as it is now?

More information is needed instead of "help fix it".


Guy Fawkes(Posted 2012) [#3]
Well. what it's doing is saving only ONE object. when it should be saving ALL objects.


Save_File(), is the one that is wrong


Rob the Great(Posted 2012) [#4]
Save_File() works as it is. If you want proof, here's the dump I was able to get after running the program:

However, I could only get it to work by fixing one small error in your code above. It's definitely a small error. In fact, it's so small, that the only difference between the correct version and the incorrect version is that a line is positioned in the wrong scope of the code, and the line only needs to be shifted down a couple of lines. Like I said, your Save_File() function is fine, but can you figure out why it would be saving only ONE object in your program? It would seem as though you only have ONE object created. Why would that be?

I'm not being mean, I'm deliberately putting emphasis on the ONE object to help you understand the problem in the code. Yes, you've created 20 different cubes, but you've only created ONE object. See if you can figure out how to solve the problem, as this is invaluable debugging experience. Every programmer has done this before, and once you figure out the problem, we can all sit back and laugh about how easy it was to fix.


Guy Fawkes(Posted 2012) [#5]
No I can't... I just tried...






Rob the Great(Posted 2012) [#6]
Take a look at this section:
;Call the type "obj"
c.obj = New obj

c\mesh = CreateCube()

;Create 20 different objects
For x = 1 To 20

;Get the total object count
c\objcount=x

;Create the cubes
c\mesh = CreateCube()
PositionEntity c\mesh,Rnd(5,50),1,Rnd(20,75)
ScaleEntity c\mesh,Rnd(0.5,1.0),Rnd(0.5,1.0),Rnd(0.5,1.0)
EntityColor c\mesh, Rnd(0,255),Rnd(0,255),Rnd(0,255)
EntityAlpha c\mesh,Rnd(0.5,1.0)
RotateEntity c\mesh,0,Rnd(0,180),0
EntityShininess c\mesh,Rnd(0.5,1.0)

Next

In English, I will reword what it is the program is currently doing:
;Keep in mind that the following two lines of code are linear, meaning they are only called once
c.Obj = New Obj ;Create a new object of the Obj type, and call it "c"
c\mesh = CreateCube() ;c's mesh value is now a cube
;
;The rest below is just psuedo because I don't want to re-write each line
;
;We're going to do the part below 20 times now...
;   Make c's number (from above) +1 each round
;   Make c's mesh value (FROM ABOVE, THE SAME OBJECT, THAT'S A BIG HINT) a new cube
;   Position, Scale, Color, Alpha, Rotate, and Make Shiny c's mesh (the same one from above)
;Go back to the start of the section, and repeat it until it's been done 20 times.

You are making 20 cubes. But you've only called the line "c.Obj = New Obj" once, which means that there is only 1 Obj to be saved. How should you reposition the line "c.Obj = New Obj" so that a new Obj is created along with every new cube you are creating?

Last edited 2012


Guy Fawkes(Posted 2012) [#7]
I DID IT! I GOT IT ROB! :D It was the LAST thing I tried :)




O happy days!


Thanks, Rob! :)


Rob the Great(Posted 2012) [#8]
Well done. The reason why I didn't just hand over the answer is because I want you to be able to reason it out on your own. Programming is hard. You have to sit down, think about it thoroughly, and then start to put the logic into Blitz. If you do it wrong, something as simple as a line being misplaced, the whole thing turns into a train wreck.

The difference between a mediocre programmer and a good programmer is that a good programmer is able to debug code quickly and effectively. But it takes a lot of practice. I'm still learning new things today, but as I continue to learn, I continue to improve on my skills. If you continue to practice debugging on your own, you'll be right up there with everyone else as far as programming goes. Don't be surprised if it takes a couple of years, though. I believe that I had been programming for about 5 years before I ever felt brave enough to help other people out on this forum.

EDIT:

I DID IT! I GOT IT ROB! :D It was the LAST thing I tried :)


Haha! That reminds me of the time that I lost my wallet. You'll never guess where I found it: it was in the LAST place I looked! lol.

Last edited 2012


Ginger Tea(Posted 2012) [#9]
What Rob did there is a practice you should adapt yourself.

Commenting code is one thing, it helps to know what is what down the line, but this ...

This is writing down in plain English what the code is doing.
Not what you want it to do or what you think it is doing, but what it is doing.

If you and this is the general you, ever get stuck with something, break the code down into English (or your written language) and write down and read it back to your self to see if anything seems amis.

The same can be reversed, someone could give a lecture on doing something to a multi programming language class, speaking only in English (or language of choice) give the class a problem to solve.

The psudo code/logical English could be written in any given programming language and the teacher could be fluent in none.
S/he would just ask you to convert the given solution into an executable file, if it runs you pass, if it doesn't you fail and have to work out why.
Translate your code back into English and see what reads wrong.

Edit:
Ninja'd

Last edited 2012


Ginger Tea(Posted 2012) [#10]
Nearly a decade ago my mum worked for people with special needs (and no I am not making a slight about whatever section of the Autistic spectrum you may be under) she told me she had to make a list of all that was involved in boiling a kettle and making a brew as some of her client's could not work without a pre written plan infront of them.

She asked me to do the same for boiling a kettle, something we take for granted and do on auto pilot, checking the water levels etc.
I actually had to revise my list as I ommited a few steps due to them being so automatic I didn't even know I was doing them.

That same list could be converted into code

You have a few factors
Variables
the water level needed, minimum for one cup max for how ever cups you can get
The time it takes the water to reach boiling point, more water more time.
Constants, the temp the kettle turns off at
And so on.

Hell I used to annoy her dog when I would take her walkies, I would list all the things I had to do in order to get ready
"I need to find my shoes"
bite *squeak* bite *squeak*
"Then I have to put my shoes on"
bite *squeak* bite *squeak* impatience ++
"Then I have to tie my laces up"
bite *squeak* bite *squeak* impatience ++
etc

In short anyone with the solution laid out infront of them can tell the class in plain language of their choice how the problem is to be solved and let them get on with it in code.

edit:
and yes the get cup subroutine involves knowing where cups are kept and cleaning a cup if necessary, no one should ever need to break out the function "go to shop and buy a cup" as who knows what cups Anne Summers sells besides those found on bra's

Last edited 2012


Ginger Tea(Posted 2012) [#11]
Nearly a decade ago my mum worked for people with special needs (and no I am not making a slight about whatever section of the Autistic spectrum you may be under) she told me she had to make a list of all that was involved in boiling a kettle and making a brew as some of her client's could not work without a pre written plan infront of them.

She asked me to do the same for boiling a kettle, something we take for granted and do on auto pilot, checking the water levels etc.
I actually had to revise my list as I ommited a few steps due to them being so automatic I didn't even know I was doing them.

That same list could be converted into code

You have a few factors
Variables
the water level needed, minimum for one cup max for how ever cups you can get
The time it takes the water to reach boiling point, more water more time.
Constants, the temp the kettle turns off at
And so on.

Hell I used to annoy her dog when I would take her walkies, I would list all the things I had to do in order to get ready
"I need to find my shoes"
bite *squeak* bite *squeak*
"Then I have to put my shoes on"
bite *squeak* bite *squeak* impatience ++
"Then I have to tie my laces up"
bite *squeak* bite *squeak* impatience ++
etc

In short anyone with the solution laid out infront of them can tell the class in plain language of their choice how the problem is to be solved and let them get on with it in code.

edit:
and yes the get cup subroutine involves knowing where cups are kept and cleaning a cup if necessary, no one should ever need to break out the function "go to shop and buy a cup" as who knows what cups Anne Summers sells besides those found on bra's

Last edited 2012


Guy Fawkes(Posted 2012) [#12]
I am on the highest spectrum of autism possible. i may have even broken it. But when it comes to CREATING something PURELY from my mind, UNLESS its SIMPLISTIC, I do NOT understand it... AT all..


Ginger Tea(Posted 2012) [#13]
You mean to say you went tartan?

Then writing it down in english first, which has been meantioned to you a fair few times, is a good starting point.

Write down what you want the program or function to do, then with your grasp of the various built in commands (and 3rd party libs you may wish to use) convert psudo code like this

is the kettle plugged in?
yes
  is it switched on at the mains?
  Yes
    Turn on Kettle
  No
    Turn on at mains, then turn on kettle
No
  Plug Kettle into mains
  and check for mains switches as above etc


into actual blitz code to do what you want.

yes the kettle thing might seem patronising, but if you write down the full procedual list involved you realise what we do on auto pilot and a program to do the same needs to be told these steps as it has no bloody idea to check for the mains if it has not been told to.

Hell urban legend has it, some guy phoned their PC tech support many years ago claiming he his pc had no power, plugs were checked and re checked.
Then brainiac informs the phone tech that there is a black out.


Gabriel(Posted 2012) [#14]
But when it comes to CREATING something PURELY from my mind, UNLESS its SIMPLISTIC, I do NOT understand it... AT all..

Try to understand that you're not different from anyone else on this point. Most of us can't create things from scratch unless it's simplistic. That's how we learn. We do simple things. We learn from it. Then we do slightly more complicated things. Your problem is that you don't have the patience to do simple things and insist on doing things you can't understand. You can't do it so you ask someone else to do it. Then you didn't do anything so you haven't learned anything. And the situation never improves.

It's like this. Either you go off and learn simple things yourself and progress slowly until you can do more advanced things. Or you spend the rest of your programming life asking other people to do everything for you, never getting any better and annoying everyone with your demanding attitude. I don't think anyone else really cares which you choose any more, but one of those options is a lot better for you.

Last edited 2012


Ginger Tea(Posted 2012) [#15]
Thundros (Posted 15 hours ago) #11

Yea.
While QUIT=1
If Keyhit(1) then QUIT = 1
Flip
Wend
End


How's THAT for BAD, Gabriel? ;)

Last edited 15 hours ago



Rob the Great (Posted 15 hours ago) #12

Hmm...
While QUIT=1 ;QUIT is not yet initialized, therefore QUIT = 0 and skips this part
   If KeyHit(1) then QUIT=1 ;Doesn't matter, because it's all been skipped
   Flip ;Doesn't matter, because it's all been skipped
Wend ;Since QUIT is not yet initialized, the program skips to here
End ;And ends.


I'm not sure that does quite what you want it to do.



Me a few posts up

What Rob did there is a practice you should adapt yourself.

Commenting code is one thing, it helps to know what is what down the line, but this ...

This is writing down in plain English what the code is doing.
Not what you want it to do or what you think it is doing, but what it is doing.


I think it's worth reiterating that part if a simple code snippet is borked so fantastically.

edit:
although there is a school of thought that that was a joke code you posted, tbh I am not sure with you.

Last edited 2012