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
if string2$="Copy" and picked>0
if string2$<>""
clone=1
endif
if clone
selectobj=cloneobj(selected+1,selected)
hide object selectobj
string2$ = ""
clone=0
endif
endif
if string2$="Paste" and picked>0
position object selectobj, object position x(selectobj)*object size x(selectobj+1), object position y(selectobj), object position z(selectobj)
show object selectobj
string2$=""
endif
Function cloneobj(newobj,obj)
clone object newobj, obj
Endfunction newobj
or possibly like this
if string2$="Copy" and picked>0
if string2$<>""
clone=1
endif
if clone
selectobj=cloneobj(selected+1,selected)
hide object selectobj
string2$ = ""
clone=0
endif
endif
if string2$="Paste" and picked>0
position object selectobj, object position x(selectobj)*object size x(selectobj+1), object position y(selectobj), object position z(selectobj)
show object selectobj
string2$=""
endif
Function cloneobj(newobj,obj)
clone object newobj, obj
Endfunction newobj
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:
do
if keystate(57)
if space_key=0
space_key=1
performaction()
endif
else
space_key=0
endif
loop
function performaction()
print "Something"
endfunction
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.