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.

DarkBASIC Professional Discussion / Copy / Paste function.

Author
Message
Mugen Wizardry
User Banned
Posted: 8th Dec 2010 17:49 Edited at: 8th Dec 2010 18:14
Hi all, I'm having a bit of a problem w/ my copy and paste commands. What I want to do is clone the object only ONCE and hide it until the user hits paste, in which case it will show the object and position it at it's original position * the size x of the copied object. i also need it when u hit copy, u can paste as many clones of an object as u want

Here's the code:



the cut / paste code is in a loop

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Mugen Wizardry
User Banned
Posted: 8th Dec 2010 21:40
Anyone? :/

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 8th Dec 2010 21:49 Edited at: 8th Dec 2010 21:51
I think everyone's given up because you aren't indenting your code so no one wants to read it to find the problem.
(You also kinda ignored our advice in the last thread you made)

Mugen Wizardry
User Banned
Posted: 9th Dec 2010 00:53
I just NOW got online. I'm sorry for not answering. At any rate, Here, I'll post the edited code.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Mugen Wizardry
User Banned
Posted: 9th Dec 2010 00:55
Done



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Dec 2010 02:23
Your indentation is all over the place, you need to come up with a format. Also you have unnecessary bits of code:

if string2$<>""
clone=1
endif

It can only get to this if string2$="Copy" and picked>0, so you know for a fact that string2$ is greater than "", so you don't need this. You shouldn't clone the object on the event of a copy, it should accrue on event of a paste. Because if you didn't want to copy an object or you clicked copy twice, you'd have objects sitting everywhere. Copy should only store the object data for the copy, then use that data for the paste. The clone object function is also unnecessary, it just slows the process down a little.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 9th Dec 2010 02:29
Seriously? That indent thing is ridiculous. Not everyone is perfect nor wants to take time out of what could be their game to indent their code. I have always hated that.

Quote: "Your indentation is all over the place, you need to come up with a format."


That's a bit picky eh?
Mugen Wizardry
User Banned
Posted: 9th Dec 2010 02:41 Edited at: 9th Dec 2010 02:41
Yea, Zeus, I totally agree. So Zeus, I don't really understand what he means. Do you think you could show me a simple example of using a key to copy, and a key to paste, and when you paste, it positions it where ever the mouse is looking?

I appreciate it!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Dec 2010 02:47
Quote: "That indent thing is ridiculous. Not everyone is perfect nor wants to take time out of what could be their game to indent their code."


Really? it's like a coding standard. The reason we indent is to make it easier to read. For instance:



We can clearly see where everything is, where as:



We can't. That's why we indent. And that's just a tiny bit of code. Just imagine 50,000 lines of code without indentation. It would take ages to go through. Then again, it kinds of is what works best for you so I guess this is your format. I'm actually impressed if you can still see where everything is. I couldn't.

Quote: "That's a bit picky eh?"


Sorry, didn't mean to be.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Mugen Wizardry
User Banned
Posted: 9th Dec 2010 02:48
It seems you all do more complaining than helping. Which is fine. I'll just wait for someone worthy to help.

Thank you anyway! ^^

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Dec 2010 03:18
Quote: "Seriously? That indent thing is ridiculous. Not everyone is perfect nor wants to take time out of what could be their game to indent their code. I have always hated that. "

Quote: "That's a bit picky eh?"

Quote: "It seems you all do more complaining than helping. Which is fine. I'll just wait for someone worthy to help. "


What.

If you need help with your code then you should make sure it's readable, otherwise it's pretty annoying to debug. Indentation is something that should be done as you code, and absolutely isn't something that detracts from coding time. Do people seriously write code at the same depth then later indent it?

No one expects perfect code, but I personally hate reading code that isn't indented(or whose indentation makes no sense) because it wastes my time as I have to re-indent it, or very slowly read it so I know what's what. And it's not just one person's time you waste, but everyone who reads it/wants to help. At least Sasuke pointed it out, I'd just expand the code box and go to a different thread.

Mugen Wizardry
User Banned
Posted: 9th Dec 2010 03:20
Ugh, I tried to be nice, but obviously I can't. NO ONE is perfect. I can't WAIT to buy nuclear basic, then maybe I won't have as many problems with you all. Because forums are for HELPING people, NOT for complaining...

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Dec 2010 03:25
Quote: "Ugh, I tried to be nice, but obviously I can't. NO ONE is perfect. I can't WAIT to buy nuclear basic, then maybe I won't have as many problems with you all. Because forums are for HELPING people, NOT for complaining..."


Did you read what I said? It's not that no one wants to help you, it's just a rather annoying hurdle to read code that isn't formatted well. You can change to whatever language you like and people will still find such indentation annoying.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Dec 2010 03:26
Quote: "Because forums are for HELPING people, NOT for complaining..."


Believe me, you won't regret taking up indenting, it's actually advice. Anyway, let's move from that topic. I wrote this quick so I didn't leave comments, but I hope you can see what's going on. If not post back with queries.



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 9th Dec 2010 03:29
Quote: "then maybe I won't have as many problems with you all. Because forums are for HELPING people, NOT for complaining..."

Were just trying to help, good coding practices are very important if you want others to read your code to help you. I mean really, we can't help you until we understand what you're trying to do. Just ignoring people who are trying to help you along the way and asking for a straight up answer is definitely not a good way to learn. You can't start running without learning to stand up first.

My computer surpasses all the technologies of the day. What computer do I have?

C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 9th Dec 2010 03:50 Edited at: 9th Dec 2010 08:05
Indentation
Sasuke and dark Coder speak the truth Mugen Wizardry, you should listen to them and you might get your answers.

Code indenting for readability is almost as strict as coding syntax for a programming language; if you do it wrong, it won't be understood.

You don't see people moaning at compilers for kicking up a fuss when the syntax is done wrong.

I also don't see how switching from DBP to another language will help you to get answers for problems. - If you go to any programming forum for help and give them a ream of unindented code you won't get anywhere.

Quote: "I'll just wait for someone worthy to help."

Pretty much everyone looking at this thread is worthy to help, but no one wants to spend the time reading through your code. - As dark coder said, we just open the code snippet, take one look and go find a different thread. (Or those of us with some patience tell you to indent it, so be thankful we're paying any attention at all - your thread could just as easily have been one of the unanswered posts you see floating around the forums because no one understands.)

Your code in the end should look like this
or possibly like this




Helping you with your code
From what I can see, this code doesn't seem to be in any context so we don't know what's going on. - If it is run, it will simply perform any checks and run into the function at the end and declare a function was hit mid-program.

In terms of actual functionality all your program seems to do is check if 2 variables are something (which they aren't as of line 1) then check the same 2 variables are something different (which they still aren't as of line 12) and hit a function which will either crash and tell you you've hit a function mid-program or clone an object that doesn't exist yet in the code and so, crashing again. (I can't remember which way DBP works, whether it'll flow into the function or close before running it.)

As we don't actually have a fully operational program/code snippet to work with (remember we don't need the whole program to fix the problem) performing the fix to:
Quote: "clone the object only ONCE and hide it until the user hits paste, in which case it will show the object and position it at it's original position * the size x of the copied object"

is virtually an impossible task.
We don't really know if the problem lies in the method the user will "hit paste" or if it is indeed in this section of code because we don't know where this code is supposed to be being used.
If it's in a loop, then the chances are the minute the user "hits paste", string2$ will presumably become "Paste" and will then check in the code you've given us if this is true.
At this point we're faced with 2 problems:
1. The call to the cloning function you've made is not inside the argument for if string2$="Paste" so it will never clone it and just try positioning an object that doesn't exist. - Resulting in crashing the program if just paste is pressed.
2. If the user is pressing a key to set the variable string2$ to "Paste", the user will still be pressing this key into the next iteration of the loop. (If your loop is running at 60 times a second or higher, the chances of the user pressing paste and releasing the key in 1 cycle are very slim because no one is that fast.)

Solving the first problem is a simple matter of another if statement to check if an object has been copied.

The way to solve the second problem (if this is indeed the main problem here) is to have a key lock as I like to call it.
This is so that it checks if the user has pressed the key once and performs an action but not if the key is still being pressed (from a previous loop iteration)
The code for this would look something like this:

This code will only run the function performaction() once each time the space key is pressed.
This is the principle for what I think you need to implement into your application and the same will apply for "Copy" as it did "Paste".
As well as all this, there are some variables to do with which object is being selected and cloned and assigned you'll need to figure out as well because all of this is missing from your code so we can't debug that for you. - It seems at the moment, regardless of how you acquire an object number for selected you are going to need to increment somehow, the number of the object it gives to the cloned version. - This will prevent it crashing when you clone the same object twice because in its current state it seems that it will assign the clone the same number, regardless of when it was cloned.



There, you got your answer. I'm not going to implement the fixes for you, that's your job as the programmer. Have fun.
Again, you also won't escape any of this by switching languages/forums.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Dec 2010 03:59
Quote: "There, you got your answer. I'm not going to implement the fixes for you, that's your job as the programmer. Have fun."




A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 9th Dec 2010 04:29
Woah, I didn't mean to start a war. I was just simply stating my opinion on the matter. To me, well commented code is perfectly readable.
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 9th Dec 2010 04:47 Edited at: 9th Dec 2010 04:54
Zeus don't worry yourself, you haven't started anything, this has been going on since Mugen Wizardry's last thread.

Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 9th Dec 2010 14:09
Oh well, my mistake. I didn't read that thread.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Dec 2010 14:16
@Mugen Wizardry,
I've already slapped you once for your behaviour. All that you need to do is be nice, especially considering the amount of help you ask for and get.

Quote: "Because forums are for HELPING people, NOT for complaining..."

But we don't have to help you, and we won't if you don't treat people with a little common decency.

One more warning, and I'll ban you.

Mugen Wizardry
User Banned
Posted: 9th Dec 2010 17:22
Thanks guys! Works great!

Except one small thing that I fixed, which allowed you to copy an object with an ID of 0 which led to a crash

Here's the new code for anyone who wants it:



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!

Login to post a reply

Server time is: 2026-07-21 19:18:29
Your offset time is: 2026-07-21 19:18:29