Çözüldü Liste verilerine rastgele değer atama

  • Konuyu Başlatan Konuyu Başlatan Shiroin
  • Başlangıç tarihi Başlangıç tarihi
  • Görüntüleme 671
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

Shiroin

Somon Balığı Selam Vermeye Geldi
Katılım
28 Ağustos 2019
Mesajlar
14
Elmaslar
2
Puan
8.710
Yaş
25

Discord:

Furkan#5593

Arkadaşlar merhaba kendim beceremedim. İstediğim şey bir fonksiyon örneğin:

{urun::1}, {urun::2} gibi verilerin bulunduğu bir liste olacak
/test komutunu kullanıldığında bu listede bulunan verilerin looplanıp her birine 1 ile 7 arasında rastgele değerler atanmasını istiyorum. Skript sürümüm son sürüm

Kod:
function test():
    set {_urunler::*} to {urun::1} and {urun::2}
    loop {_urunler::*}:
        set {_urunler::%loop-index%} to random integer between 1 and 7
Böyle bir şey denemiştim ama muhtemelen kodu yanlış yazdım. Şimdiden teşekkürler.
 
Kod:
ürün_listesi:
  - "{urun::1}"
  - "{urun::2}"
  - "{urun::3}"

Öncelikle ürünlerini bulunacağı liste.

Kod:
command /test:
  trigger:
    loop player with urun in file "plugins/Skript/ürün_listesi.yml":
      set {_random} to a random integer between 1 and 7
      message "%urun%: %{_random}%"

Deneyebilirsin
 
Kod:
ürün_listesi:
  - "{urun::1}"
  - "{urun::2}"
  - "{urun::3}"

Öncelikle ürünlerini bulunacağı liste.

Kod:
command /test:
  trigger:
    loop player with urun in file "plugins/Skript/ürün_listesi.yml":
      set {_random} to a random integer between 1 and 7
      message "%urun%: %{_random}%"

Deneyebilirsin

Screenshot_1.png

Öncelikle cevabın için teşekkürler ancak şöyle bir hata alıyorum, eğer skript-yaml addon'u lazımsa kullanamıyorum çünkü sunucu 1.20.4 sürümlü ve o addonu bu sürümde çalıştıramadım.
 
[18:10:02 INFO]: Can't understand this loop: 'player with urun in file "plugins/Skript/ürün_listesi.yml"'
[18:10:02 INFO]: Line: loop player with urun in file "plugins/Skript/ürün_listesi.yml":
Hatayı yazı olarak atabilir misin bir hata nedeniyle telefonumdan fotoğraflara bakamıyorum.
 
Kod:
command /test:
  trigger:
    loop files in folder "plugins/Skript" matching "ürün_listesi.yml":
      loop lines of file loop-file:
        set {_random} to a random integer between 1 and 7
        message "%loop-line%: %{_random}%"

Şu şekilde düzenleyebilirsin kodu ayrıca ürün_listesi.yml oluşturdum değil mi?
 
Kod:
command /test:
  trigger:
    loop files in folder "plugins/Skript" matching "ürün_listesi.yml":
      loop lines of file loop-file:
        set {_random} to a random integer between 1 and 7
        message "%loop-line%: %{_random}%"

Şu şekilde düzenleyebilirsin kodu ayrıca ürün_listesi.yml oluşturdum değil mi?

Yine aynı hatayı alıyorum ve evet listeyi oluşturdum
 
Kod:
command /test:
    trigger:
        set {_file} to new java.io.File("plugins/Skript/ürün_listesi.yml")
        set {_lines} to read {_file} line by line
        loop {_line::*} through {_lines}:
            set {_random} to a random integer between 1 and 7
            message "%{_line::*}%: %{_random}%"

Şunu deneyelim birde
 
Kod:
command /test:
    trigger:
        set {_file} to new java.io.File("plugins/Skript/ürün_listesi.yml")
        set {_lines} to read {_file} line by line
        loop {_line::*} through {_lines}:
            set {_random} to a random integer between 1 and 7
            message "%{_line::*}%: %{_random}%"

Şunu deneyelim birde

Kod:
[18:25:50 INFO]:     Can't understand this expression: 'new java.io.File("plugins/Skript/ürün_listesi.yml")'

[18:25:50 INFO]:     Line: set {_file} to new java.io.File("plugins/Skript/ürün_listesi.yml")

[18:25:50 INFO]:

[18:25:50 INFO]: Line 29: (Test.sk)

[18:25:50 INFO]:     Can't understand this expression: 'read {_file} line by line'

[18:25:50 INFO]:     Line: set {_lines} to read {_file} line by line

[18:25:50 INFO]:

[18:25:50 INFO]: Line 30: (Test.sk)

[18:25:50 INFO]:     Can't understand this loop: '{_line::*} through {_lines}'

[18:25:50 INFO]:     Line: loop {_line::*} through {_lines}:
 
Moderatör tarafından düzenlendi:
[18:25:50 INFO]: Can't understand this expression: 'new java.io.File("plugins/Skript/ürün_listesi.yml")'
[18:25:50 INFO]: Line: set {_file} to new java.io.File("plugins/Skript/ürün_listesi.yml")
[18:25:50 INFO]:
[18:25:50 INFO]: Line 29: (Test.sk)
[18:25:50 INFO]: Can't understand this expression: 'read {_file} line by line'
[18:25:50 INFO]: Line: set {_lines} to read {_file} line by line
[18:25:50 INFO]:
[18:25:50 INFO]: Line 30: (Test.sk)
[18:25:50 INFO]: Can't understand this loop: '{_line::*} through {_lines}'
[18:25:50 INFO]: Line: loop {_line::*} through {_lines}:

Kod:
command /test:
    trigger:
        set {_lines} to ["ürün 1", "ürün 2", "ürün 3"] # Ürün listesini elle girin veya dosyadan okuyun
        loop {_line} through {_lines}:
            set {_random} to a random integer between 1 and 7
            message "%{_line}%: %{_random}%"

Demeyelim
 
Kod:
command /test:
    trigger:
        set {_lines} to ["ürün 1", "ürün 2", "ürün 3"] # Ürün listesini elle girin veya dosyadan okuyun
        loop {_line} through {_lines}:
            set {_random} to a random integer between 1 and 7
            message "%{_line}%: %{_random}%"

Demeyelim


Yine
Can't understand this condition/effect ve Can't understand this loop

hatası alıyorum öncekiler gibi
 
Kod:
command /test:
    trigger:
        set {_lines::*} to ["{urun::1}", "{urun::2}", "{urun::3}"] # Ürün listesini elle girin veya dosyadan okuyun
        loop {_line::*} through {_lines::*}:
            set {_random} to a random integer between 1 and 7
            broadcast "%{_lines::%loop-index%}%: %{_random}%"
Şunu deneyelim
 
Kod:
command /test:
    trigger:
        set {_lines::*} to ["{urun::1}", "{urun::2}", "{urun::3}"] # Ürün listesini elle girin veya dosyadan okuyun
        loop {_line::*} through {_lines::*}:
            set {_random} to a random integer between 1 and 7
            broadcast "%{_lines::%loop-index%}%: %{_random}%"
Şunu deneyelim


Kod:
[18:50:36 INFO]: Line 28: (Test.sk)

[18:50:36 INFO]:     Can't understand this condition/effect: set {_lines::*} to ["{urun::1}", "{urun::2}", "{urun::3}"]

[18:50:36 INFO]:     Line: set {_lines::*} to ["{urun::1}", "{urun::2}", "{urun::3}"]# Ürün listesini elle girin veya dosyadan okuyun

[18:50:36 INFO]:

[18:50:36 INFO]: Line 29: (Test.sk)

[18:50:36 INFO]:     Can't understand this loop: '{_line::*} through {_lines::*}'

[18:50:36 INFO]:     Line: loop {_line::*} through {_lines::*}:
 
Moderatör tarafından düzenlendi:
[18:50:36 INFO]: Line 28: (Test.sk)
[18:50:36 INFO]: Can't understand this condition/effect: set {_lines::*} to ["{urun::1}", "{urun::2}", "{urun::3}"]
[18:50:36 INFO]: Line: set {_lines::*} to ["{urun::1}", "{urun::2}", "{urun::3}"]# Ürün listesini elle girin veya dosyadan okuyun
[18:50:36 INFO]:
[18:50:36 INFO]: Line 29: (Test.sk)
[18:50:36 INFO]: Can't understand this loop: '{_line::*} through {_lines::*}'
[18:50:36 INFO]: Line: loop {_line::*} through {_lines::*}:

Sanırım skript ile yapamıyoruz şöyle bir plugin yapabiliriz.

Kod:
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MyPlugin extends JavaPlugin {

    private List<String> urunListesi;

    @Override
    public void onEnable() {
        // Eklenti etkinleştirildiğinde çalışacak kodlar buraya yazılabilir.
        // Ürün listesini burada oluşturabilir veya başka bir kaynaktan yükleyebilirsiniz.
        urunListesi = new ArrayList<>();
        urunListesi.add("{urun::1}");
        urunListesi.add("{urun::2}");
        urunListesi.add("{urun::3}");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("test")) {
            // /test komutu kullanıldığında çalışacak kodlar buraya yazılabilir.
            Random random = new Random();
            for (String urun : urunListesi) {
                int randomDeger = random.nextInt(7) + 1; // 1 ile 7 arasında rastgele bir değer oluştur
                sender.sendMessage(urun + ": " + randomDeger);
            }
            return true;
        }
        return false;
    }
}
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

Hala Discord sunucumuza katılmadın mı?

Büyük bir topluluğun parçası ol, etkinliklere katıl ve özel hediyeler kazanma şansı yakala!

Şimdi Katıl
Üst