Scratch739201

How can I set X and Y position of a variable? Or let the variable gilde or move?

I wish there's a block like this:

set x: (100) y:(-25) for [my-var v] :: variables

let [my-var v] glide to x: (25) y: (-55) :: variables

Thejbomber

You can't; you can click and drag it to a spot. To create the illusion of it, you can create a small sprite, like a black dot, set it to, say, 0,0, and just put the variable over it. No, you cannot move a variable by a block.

Scratch739201

Thejbomber wrote:

To create the illusion of it, you can create a small sprite, like a black dot, set it to, say, 0,0, and just put the variable over it.

What should the black dot do??? I don't know why a black dot should do anything with a variable. Can you please explain why?

Thejbomber

You put the variable expression (the box with a number) over the black dot. That way, you can tell exactly where the variable is.

Scratch739201

liKe a marKer right?

Dinosaur_Weirdo

Yes, I would love this. For an online multiplayer thing with something like…
(being a button for player 1)
when this sprite clicked
set [player selected] to [1]
(being a sprite that moves with certain keys, eg player 1)
when green flag clicked
forever
if <(player selected) = [1]>
set [☁ player 1 username] to (username)
show variable [☁ player 1 username]
stop [this script]
when green flag clicked
forever
set [☁ p1x] to (x position)
set [☁ p2x] to (y position)
set x of [☁ player 1 username] to (☁ p1x)
set y of [☁ player 1 username] to <(☁ p1y) - [5]>
…would be great for having a username underneath a sprite.
However, due to limitations of cloud variables, we would not be able to set a variable to a username unless the username contained only numbers, which is unlikely.
Darn.
But the concept is still cool, right?
Also, setting the view of the variable (large readout, normal readout or slider) with something like
when green flag clicked
set type for [☁ player 1 username] to [small]
would be pretty nice.
Support.

deck26

Dinosaur_Weirdo wrote:

Yes, I would love this. For an online multiplayer thing with something like…
(being a button for player 1)
when this sprite clicked
set [player selected] to [1]
(being a sprite that moves with certain keys, eg player 1)
when green flag clicked
forever
if <(player selected) = [1]>
set [☁ player 1 username] to (username)
show variable [☁ player 1 username]
stop [this script]
when green flag clicked
forever
set [☁ p1x] to (x position)
set [☁ p2x] to (y position)
set x of [☁ player 1 username] to (☁ p1x)
set y of [☁ player 1 username] to <(☁ p1y) - [5]>
…would be great for having a username underneath a sprite.
However, due to limitations of cloud variables, we would not be able to set a variable to a username unless the username contained only numbers, which is unlikely.
Darn.
But the concept is still cool, right?
Also, setting the view of the variable (large readout, normal readout or slider) with something like
when green flag clicked
set type for [☁ player 1 username] to [small]
would be pretty nice.
Support.
Every cloud list project encodes and decodes usernames so they can be stored in cloud variables.

Dinosaur_Weirdo

deck26 wrote:

Dinosaur_Weirdo wrote:

Yes, I would love this. For an online multiplayer thing with something like…
(being a button for player 1)
when this sprite clicked
set [player selected] to [1]
(being a sprite that moves with certain keys, eg player 1)
when green flag clicked
forever
if <(player selected) = [1]>
set [☁ player 1 username] to (username)
show variable [☁ player 1 username]
stop [this script]
when green flag clicked
forever
set [☁ p1x] to (x position)
set [☁ p2x] to (y position)
set x of [☁ player 1 username] to (☁ p1x)
set y of [☁ player 1 username] to <(☁ p1y) - [5]>
…would be great for having a username underneath a sprite.
However, due to limitations of cloud variables, we would not be able to set a variable to a username unless the username contained only numbers, which is unlikely.
Darn.
But the concept is still cool, right?
Also, setting the view of the variable (large readout, normal readout or slider) with something like
when green flag clicked
set type for [☁ player 1 username] to [small]
would be pretty nice.
Support.
Every cloud list project encodes and decodes usernames so they can be stored in cloud variables.
This is true, but I myself am still fairly new to Scratch and although I have looked at them, I have not been able to figure them out.
Any help on this would be greatly appreciated.
Thanks!

camck

Use a text engine

https://scratch.mit.edu/projects/66904754/

They look cooler too

Mr_PenguinAlex

Derp

TheCookieHero880

camck wrote:

Use a text engine

https://scratch.mit.edu/projects/66904754/

They look cooler too

I agree, you should use a text engine, sprites which write out variable texts. It allowes for moving of variables as well as much more customisation.

Ayarkay

Well a variable simply stores a number, and a number doesn't have an x or a y value. It only has one value, which is that number's value.

If you wanted to use variables to represent coordinates, you'd need to have 2 separate variables, representing x and y respectively.


As far as making things glide goes, when you think about it, when an object glides from point A to point B, what happens is that A's x value slides to B's x value, and A's y value slides to B's y value. In order to glide from one value to another, we need to be able to create a system which takes in a starting number, and ending number, and the number of steps you want it to take before it reaches the ending number (the glide speed).

So:

Let a = the starting number
Let b = the ending number
Let t = the glide time

So we want to glide from a -> b in t amount of time.


( |(a-b)| / t ) * x + a

Here, if you input a, b, and t, you can iterate x all the way up to t in order to interpolate its value at all points between 0 and t.

So if you wanted to glide between 2 xy coordinates, you'd run the above formula for the x-values and the y-values separately, but have the glide time be the same for both.

TheKingRafael

Ayarkay wrote:

Well a variable simply stores a number, and a number doesn't have an x or a y value. It only has one value, which is that number's value.

If you wanted to use variables to represent coordinates, you'd need to have 2 separate variables, representing x and y respectively.


As far as making things glide goes, when you think about it, when an object glides from point A to point B, what happens is that A's x value slides to B's x value, and A's y value slides to B's y value. In order to glide from one value to another, we need to be able to create a system which takes in a starting number, and ending number, and the number of steps you want it to take before it reaches the ending number (the glide speed).

So:

Let a = the starting number
Let b = the ending number
Let t = the glide time

So we want to glide from a -> b in t amount of time.


( |(a-b)| / t ) * x + a

Here, if you input a, b, and t, you can iterate x all the way up to t in order to interpolate its value at all points between 0 and t.

So if you wanted to glide between 2 xy coordinates, you'd run the above formula for the x-values and the y-values separately, but have the glide time be the same for both.

Well.. That must be awesome, but this guy was talking about moving the “casing” of a variable showing its value ingame.
————————————————————————————————————————————————————————————————-

Personally, I always use number sprites to show the value of the variable where-ever I want. It's easy to move around and it looks better. The disadvantage is that it's a little harder to make, but Scratch is made to learn from, so this is a nice opportunity to do so, I think!

Ayarkay

Haha my bad.

SuperCDI

So you know the scrolling type variable I wondered if you can make a sprite move from that variable! Please reply

Uniquename1

Didn't read all the other stuff you can make a little dot move it about and use the
say (foo)
blocks.

RLCAnika19

do you need a background that you made, or can you use one that scratch made to find the x and y coordinates? plz help, because I need it for a project!

check out my games!
flying kitty cat maze
Get The Puppy Home!!!! the one with the green background, and has black and blue.
the story of how Voldemort got moldy!!! A Harry Potter story

The Gray and Blue. A civil war Question and Answer thing.

codeman1044

Please don't necropost. This topic's last post is from 2017.