Discord
Login
Community
DARK THEME

help please

I'm trying to make a game where you jump between lines and doge objects but the problem is I'm new to this. I'm using js and when I try to move my character nothing happens heres my code

var blockyX = -14

draw = function() {

//lines screen.clear("white") screen.setLineWidth( 5 ) screen.drawLine(100, 500, 100, -100, "red"); screen.drawLine(0, 500, 0, -100, "red") screen.drawLine(-100, 500, -100, -100, "red")

screen.drawSprite( "blocky", blockyX, -75, 300, )

var movement = function() { if (keyIsPressed && keyCode === RIGHT) { blockyX = 86 } else { blockyX = -14 } } }

ps. how do take pictures of your code to put on here? I've seen it on other posts I just cant figure out how

To format code on the forums, enclose it in triple backticks (```).

Markdown:

```
print("hello world")
```

Result:

print("hello world")

First, I'd recommend using microscript instead of javascript, as it can act unreliable in the context of microstudio. Here, it is been properly rewritten in microstudio, I also slightly modified it. Now, it instead creates a compact array called blockyX, which contains X coordinates for where it has to go. blockyI here is simple the index. When hitting A or D (or the left and right arrow), you'll decrease / increase the index, causing your character to move correspondingly. I also put in a simple detection to avoid going outside the list.

init = function()
  blockyX = [-114, -14, 86]
  blockyI = 1
end

movement = function()
  if (keyboard.press.RIGHT and blockyI < blockyX.length - 1) then
    blockyI += 1
  elsif (keyboard.press.LEFT and blockyI > 0) then
    blockyI -= 1
  end
end

update = function()
  _2_movement()
end

draw = function()
  //lines
  screen.clear("white")
  screen.setLineWidth(5)
  screen.drawLine(100, 500, 100, -100, "red")
  screen.drawLine(0, 500, 0, -100, "red")
  screen.drawLine(-100, 500, -100, -100, "red")
  screen.drawSprite("icon", blockyX[blockyI], -75, 32)
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community