Page 1 of 1

movement using arrow keys

Posted: Sun Nov 17, 2013 1:33 pm
by chris25
On ArrowKey x etc etc etc.....Is there a method to move an object smoothly, without that pixel per pixel jiddery movement one usually gets. I have done it with the Move command when setting pre-defined paths from one x-y co-ordinate to another, and I have done it on a random movement using a series of get repeat and put commands. But these are pre-defined movements, not controlled with the arrow keys. That was the first question.

Second question I think is a No, but I'll try anyway. When using the arrow keys IF the above is possible, I would like to achieve the following effect:

User pushes right arrow key and object moves from a standstill position and slowly speeds up (No rocket speed, a sort of submarine speed), and when he removes his finger from the right arrow key the object starts to slow down at the same rate until a complete stop, if at any time he presses the right arrow before the object has stopped the object speeds up again to a pre-defined maximum speed. Does this sound like too much without having to learn the animation engine?

Trust me, it is a very very simple game, but due to its simplicity I want to offset that with some strategy and inject some creative interest. It's both an exercise and for the time being a little fun - I hope.

Chris

Re: movement using arrow keys

Posted: Sun Nov 17, 2013 6:52 pm
by dunbarx
Hi.

Pretty crude. I just wanted to test adding a couple of custom properties to set the "velocity" of the object movement. Pretty jerky, it needs to have that value scaled back, perhaps tied to the initial loc, and incremented as a percentage of the offset of that loc. Just a single button on a card, this in the card script:

Code: Select all

on arrowkey tKey
   if tKey = "right" then
      if the  direction of btn 1 = "left" then set the velocity of btn 1 to 1
      set the direction of btn 1 to "right"
      set the left of btn 1 to the left of btn 1 +  the velocity of btn 1
      set the velocity of btn 1 to the velocity of btn 1 + 1
   end if
   if tKey = "left" then
      if the  direction of btn 1 = "right" then set the velocity of btn 1 to 1
      set the direction of btn 1 to "left"
      set the left of btn 1 to the left of btn 1 -  the velocity of btn 1
      set the velocity of btn 1 to the velocity of btn 1 + 1
   end if
end arrowkey
Needs work...

Craig

Re: movement using arrow keys

Posted: Sun Nov 17, 2013 7:37 pm
by chris25
Hallo Craig,

Firstly, thankyou. Secondly, well, I am reluctant to just take something and apply it and say thankyou if I do not understand the reasoning behind it. Now obviously my first port of call was to look up direction and velocity in the dictionary - which well don't exist. But you also mentioned that you set custom properties about which I have not yet been able to really understand. Then reading this script is mind blowing to say the least because no matter how hard I try, I just can not understand the twist and turns: for example: This is so Backward logic but of course I know it is perfectly reasonable for the experienced coder:
if the direction of btn 1 = "left" then set the velocity of btn 1 to 1
set the direction of btn 1 to "right"

Hope you understand what I am trying to say, not just copy, but understand the reasoning and how on earth you arrived at it given that not a single word here can be looked up (apart from the handler itself and the name:'button')

kind regards
chris

Re: movement using arrow keys

Posted: Sun Nov 17, 2013 9:22 pm
by jmburnod
Hi Chris,

"the velocity" and "the direction" are two custom properties of btn 1 created by the Craig's script

Jean-Marc

Re: movement using arrow keys

Posted: Sun Nov 17, 2013 9:34 pm
by dunbarx
Chris.

Partly my fault. You have started to get hold of the language, and I throw in words that seem to be native to LC, but are not. A custom property is one that you define, similar to a variable that you make up. You have no issue, I assume (any longer) if I write:

put 32 into garbage. ("Garbage", you now know, is a variable name made up on the spot, and hopefully is named in such as way as to be useful.)

A custom property, and these are among the most powerful and useful gadgets in LC, are just like native properties, but you make them up. Of these three lines:

the loc of button 1
the textSize of field 3
the gobbledygook of image 2

Which is not native to LC?

Now "velocity" and "direction" sound native, but are not. They are just names of a custom property that holds a value. Unlike global variables, custom properties are always married to objects. They survive between sessions, and are like the text of a field in that way. I made these two because it was convenient. I can set or get their values at any time.

So think of these as you think of the contents of a field. Invisible, they hold a value forever. You will find soon that they just fit the bill for a task you are working on. They also can hold much more than text, as you might find out if you research them.

Craig

EDIT.

Hey, just do this yourself. Make a button. Make up a custom property by just setting a value to that property. Now "get" that property. Now set that property to something naturally related to its value, like adding 1 to it if it was a number. Note that this has to be done with "set" and "get". These are not containers. You cannot, say, "add 1 to the currentInteger of btn 1"

Re: movement using arrow keys

Posted: Sun Nov 17, 2013 11:14 pm
by chris25
Thanks Craig, very much, I'm on it, doing my homework. I had read about custom properties but the language that was used to describe what was happening was confusing. I have to say your explanation is straight to the point, simple and understandable.

Re: movement using arrow keys

Posted: Mon Nov 18, 2013 12:12 am
by chris25
ok Craig, theory is great, but having difficulty grasping the actual 'doing', it looked straightforward when I read it, but this is what I did, but don't think I have used custom properties - so am still bewildered here.

on mouseUp
if the arcangle of grc "oval" is 179 then
set the arcangle of grc "oval" to 250
end if
end mouseUp
========these bottom two were supposed to connect.
--on drawline
--wait 3 seconds
--set arcangle of grc "oval" to 250
--end drawline

--on mouseUp
--get drawline
--put drawline into grc "oval"
--end mouseUp

edit: I should add Craig that I have read quite a lot about custom and setprop and getprop and while the literature is great at telling you what it does, and tells you what it is, there really is scant information in teaching you How you actually use it in a practical environment other than a few lines of syntax.

Re: movement using arrow keys

Posted: Mon Nov 18, 2013 2:37 am
by dunbarx
Your topmost mouseUp handler looks OK. Any issues?

For the second pair of handlers: In the mouseUp handler you ask to "get drawLine". Does "drawLine" exist, and does it contain information? More basically, is it a variable that was loaded somewhere else? If so is it declared local or global in the script? "Getting" puts whatever might be in a variable named "drawLine" into the local "it" variable.

The reason I ask is because you also have a "drawLine" handler. This seems fine as it stands, but is it that you cannot call it from that mouseUp handler? Why not just:

Code: Select all

on mouseUp
drawLine
end mouseUp
That is how you call another handler. Uncomment the "drawline" handler and run the new "mouseUp" handler. Should be fine.

You cannot put a value into a graphic. Graphics are not containers. Fields and buttons are containers, though, and you could do that with those. Is "container" something you are familiar with?

You are getting there. You have a little way to go.

Craig

Craig

Re: movement using arrow keys

Posted: Mon Nov 18, 2013 9:59 am
by chris25
Morning Craig,

Yes the topmost one worked fine. And the underneath ones worked fine once I took the get out of the way. Drawline, then, was a variable that I defined and not a custom property? I understand that get returns the 'it' varibale in some contexts, but I was trying to use it in the context of custom property.

Yes I pretty much understand containers as variables. Text fields and buttons I did not see as containers. Then pbviously I totally misunderstand the meaning of the word 'Value' in fact this is not the first time I have done this, the trouble I am finding that I am having still to make quite some mental leaps in Re-Definig common English meanings of some words because it does not carry the same meaning in the programming world. I saw the oval as having the obvious Values instead of a text field because mathematically speaking it is full of values, hence I dived straight in to that instead of a text field.


So if you can not have a custom property for a graphic (grc) because you can not put a value into a graphic (strange as that sounds to me), we take not a text field, but an 'action'. Basd on:

if the property of object is propvalue
put property of object into container
get property of object set the property of object to propvalue (this last one is easy)

I take a ball falling by using a move command, the ball has to be a button otherwise I can not change its value? midway I want to change its shape, but I can not because it needs to be an oval - ah, catch 22. Try something else, the ball (button) falls, what value can I give a button? that does not already exist available to me in the properties box already? Lets take a button disguised as a boat in a game, I want the boat to sink, you see I could do this I do not need custom properties, this is my first problem I can not think of any custom properties to make up. You move button with arrow keys in nthe script you gave me above, so there you had to make a custom property I see that now, but how the hell did you ever come up with that syntax where you would have to defy the laws of physics (as written grammatically) to get the buttons to move like that in the first place? I mean if the direction of button 1 is left, then it's pretty much a forgone conclusion that it is not going to go right isn't it? :? So you came up with a custom property? Wow, shall I just give up now? :roll:

What I did, did not really teach me anything new to be honest, I already knew this; So any chance I could have an ABC demonstration of how a custom property would be used in practise in a real world situation with a couple of examples of variation so that I can build up a mental picture, within which I can then understand enough in order to stand on my own two feet. :)

I read a couple of reviews from people weeks ago when I was researching out LC for the first time that LC teaching was a painful process - I had no idea I would be stuck in a dungeon though. :) It's not LC itself or its language it is the learning process is not facilitated really with tutorials, just by really kind guys on a forum and yes excellent references; once you are a year into it I suppose, then, they become a gold mine of resources. So I am forced to embarrass myself each time with questions that are, I suppose, so basic for most, I would rather read and ask questions than put most of my reliance on a forum, but I have no choice. I once found LC TV and thought wow...finally what a fantastic thing (having been brought up with adobe TV), you could imagine how disappointed I was, nothing to do with teaching at all - so here I am. again and again.

Kindest regards
chris

Re: movement using arrow keys

Posted: Mon Nov 18, 2013 1:29 pm
by chris25
Ok, custom properties can be glued to a particular object and travel with it, a variable can not. Yet a variable can also be persistent if it is global, so no difference here? A custom property can ONLY be truly recognised by the addition of the definite article 'The', without this we know that it is not a custom property. As long as someone does not stick a 'The' onto a variable which is allowed. I actually read that variables perform faster than custom properties so one would prefer, if possible, to use a variable instead of a custom property in a dynamic situation, static situations then custom properties/variables take your pick if you can?

Understanding the above highlights I think why I was finding it difficult to recognise a custom property or a variable, sometimes, in other scripts. But this is no excuse since I confess that I was having trouble seeing the logical progression of thought and logic at the very point a custom property was being used and then working out how it was originally designed and for what it was purposed. So far there seems to be little difference in the architecture of the script layout and definitions between a variable and a custom property. But yet when I look at your script Craig in the example above, I really confess that I would not know how to do this using variables, so it would be nice to see if it can be done with variables, then I would be able to perhaps visually appreciate something, I don't know.

So basically, variables are better than custom properties since they are almost identical and do almost the same thing, except for that one difference above where a Custom property can be stuck on the back of an object and travel with that object all over the application whenever it is needed, hence in this context, a Custom property is powerful. But this is the only advantage I have been able to fathom so far in my limited experience and ignorance. :)

Re: movement using arrow keys

Posted: Mon Nov 18, 2013 4:28 pm
by dunbarx
Chris.

I guess I keep doing this. "Value" is a reserved word in LC, in other words, a native word. I used the term in its ordinary sense, I can see how this might be confusing to a new user who wants clarity above all else.

You can indeed ascribe a custom property to a graphic. But you cannot put anything "into" it, as it is not a container. A button, for whatever reason, and this goes back to HC days, is a true container, and you can:

put "ABC" into button "yourButton" (Just like you can do so with a field.) And then you can: answer button "yourButton", and you will get the "ABC" back.

But this is not a custom property of that button, only the contents of that button. A separate feature, if you will. You can always add custom properties, as many as you like, to that button as well, and these properties survive the session. Further, they are available ubiquitously, as opposed to even a global variable, in that you can access them from anywhere at any time. Just like any property. They live with the object, and are open to anything that needs them.

Variables are not better than custom properties, just different. Just wait, you will find a perfect need for them one day soon, where a variable just does not cut it. Then you will know...

Craig

Re: movement using arrow keys

Posted: Mon Nov 18, 2013 5:42 pm
by chris25
Okay, thankyou Craig.

Re: movement using arrow keys

Posted: Wed Nov 20, 2013 3:59 pm
by dunbarx
Chris.

Check out a new thread on this forum: "populating...

I gave an example where custom properties just fit the bill. Try to do this with variables. You really cannot without help from somewhere else, like a field.

Craig

Re: movement using arrow keys

Posted: Wed Nov 20, 2013 6:57 pm
by chris25
Hi Craig,
only relevant populating reference I can find is "button script" on 11 november, do you mean this?
regards
chris