How to new file

Hi @Sans_On,

Good morning from Canada!

Try:

use_synth :piano
3.times do
  play_chord [:d4, :d5]
  sleep 0.25
end

See what’s different? Programming can be hard. Computers are picky. You must pay attention. Don’t give up!

Thank you. Can be used.

1 Like

Please teach me to fix it.
@d0lfyn piano
use_synth :piano
3.times do
play_chord [:d4, :d5]
sleep 0.25
play_chord( :D5, :major)
sleep 0.5
play_chord( :D5, :major)
sleep 0.25

play_chord( :A, :major)
sleep 0.5
play_chord( :A, :major)
sleep 0.5

play_chord( :G, :major)
sleep 0.5
play_chord( :G, :major)
sleep 0.5

play_chord( :A, :major)
sleep 1
end

#Faster Piano
8.times do
play_chord( :G, :major)
sleep 0.25
end

8.times do
play_chord( :A, :major)
sleep 0.25
end

play_chord( :D5, :major)
end

Hi,

In coding you have to take care of the syntax, a space can be enough to break the script.
So i just indicate the good syntax for the begining then you will have to write yourself the whole code, it’s how you can learn by do it yourself
So

use_synth :piano
3.times do
  play_chord [:d4,:d5]
  sleep 0.25
  play_chord chord(:D5, :major)
  sleep 0.5
end

You have missed the chord instruction and you have added a wrong space before the root note :D5.
Good luck

1 Like

You’re welcome! You can learn a lot from the kind people here if you are courteous. You should also read the tutorial first. People can be busy.

I will run your program and show you how to fix the errors one by one.

First:

This means there is an extra end on line 36. Let’s take it out.

image

Next:

This means on line 5, you’re using play_chord wrong. You’re very close.

Let’s look at the documentation for the play_chord function. Go to Help > Lang, and look for play_chord.

image

If you look at example 3, you’ll find what you’re missing. (@nlb pointed this out too, so make sure to thank them!)

image

Let’s try.

use_synth :piano
3.times do
  play_chord [:d4, :d5]
  sleep 0.25
  play_chord chord(:D5, :major)
  sleep 0.5
  play_chord chord(:D5, :major)
  sleep 0.25
  
  play_chord chord(:A, :major)
  sleep 0.5
  play_chord chord(:A, :major)
  sleep 0.5
  
  play_chord chord(:G, :major)
  sleep 0.5
  play_chord chord(:G, :major)
  sleep 0.5
  
  play_chord chord(:A, :major)
  sleep 1
end

#Faster Piano
8.times do
  play_chord chord(:G, :major)
  sleep 0.25
end

8.times do
  play_chord chord(:A, :major)
  sleep 0.25
end

play_chord chord(:D5, :major)

This works because chord(:D5, major) gives you [74, 78, 81].

There’s your I-V-IV-V, IV-V-I.

Thank you very much… I’ll try it again.
@nlb
@d0lfyn

1 Like

how to fix
#Faster Bass
8.time do
play :G2, release: 0.25 amp: 0.5
sleep 0.25
end

8.time do
play :A2, release: 0.25 amp: 0.5
sleep 0.25
end

play[:D2, amp: 0.5]
end

[Runtime Error: [buffer 0, line 830] - SyntaxError
Thread death!
workspace_zero:71: syntax error, unexpected tIDENTIFIER, expecting keyword_end
play :G2, release: 0.25 amp: 0.5
^~~
workspace_zero:73: syntax error, unexpected keyword_end, expecting end-of-input
end
^~~
] @d0lfyn

Again, computers are picky. You must pay attention. Let’s start from the top:

  1. It’s 8.times not 8.time
  2. Each “argument” for a function like play needs a comma. See what’s different here? play :G2, release: 0.25, amp: 0.5
  3. play[:D2, amp: 0.5] is not how you use play. Let’s look at the documentation for play in Help > Lang > play. Example 3 looks like this: play 62, pan: -1, release: 3. You should follow that. play :D2, amp: 0.5
  4. You have an extra end at the end of your code. Let’s remove it.

If you fix everything, you will get this. (Try to figure it out before you look at the answer.)

#Faster Bass
8.times do
  play :G2, release: 0.25, amp: 0.5
  sleep 0.25
end

8.times do
  play :A2, release: 0.25, amp: 0.5
  sleep 0.25
end

play :D2, amp: 0.5
2 Likes

hello,

you have to remember that an end is always with a do as the do and the end creates a block. Inside this block you can write all the code you want to be as example repeated.
For the latest line, you don’t need a block as the instruction is used only once. So no do neither end.
Follow the tutorials, you will learn very fast. believe me.
good luck

The only times when this is not true is when you are using if and for. For example:

for i in 0..2
  if i.even?
    puts i.to_s + " is even"
  end
end

I agree! If you really do want to learn to use Sonic Pi, you will have to do some work.

Good luck!

Yep. Absolutely ! I was too much focused on the times case

1 Like