Programmiersprache – die besten Beiträge

Habe einen komischen Fehler in VHDL, welcher so nicht auftreten sollte?

Bei mir komm tin VHDL der Folgende Fehler, bei folgendem Code, und ich kann mir nicht erklären warum

line 36:5:warning: instance "low_counter" of component "genericcounter" is not bound [-Wbinding]
    low_counter: GenericCounter123
    ^
line 14:14:warning: (in default configuration of sekundenzaehler(rtl))
line 49:5:warning: instance "high_counter" of component "genericcounter123" is not bound [-Wbinding]
    high_counter: GenericCounter123
    ^
line 14:14:warning: (in default configuration of sekundenzaehler(rtl))

-----
ERROR: ELABORATION
Folgender Code wurde analysiert:
    1:  library ieee;
    2:  use ieee.std_logic_1164.all;
    3:  use ieee.numeric_std.all;
    4:  
    5:  entity SekundenZaehler is
    6:      port(
    7:          clk : in std_logic;
    8:          reset : in std_logic;
    9:          count_1 : out std_logic_vector(3 downto 0);
   10:          count_10 : out std_logic_vector(3 downto 0)
   11:      );
   12:  end SekundenZaehler;
   13:  
   14:  architecture rtl of SekundenZaehler is
   15:  
   16:  component GenericCounter is
   17:          generic (
   18:              Count_max : integer
   19:          );
   20:          port(
   21:              clk : in std_logic;
   22:              enable : in std_logic;
   23:              reset : in std_logic;
   24:              count : out std_logic_vector(3 downto 0);
   25:              overflow : out std_logic
   26:          );
   27:  end component;
   28:  
   29:  --Zähler und Overflowsignale
   30:      signal five_count : std_logic_vector(3 downto 0);
   31:      signal nine_count : std_logic_vector(3 downto 0);
   32:      signal five_overflow : std_logic;
   33:      signal nine_overflow : std_logic;
   34:  
   35:  begin
   36:      low_counter: GenericCounter
   37:      generic map (
   38:          Count_max => 9  -- Zählt von 0 bis 9 (Einerstelle)
   39:      )
   40:      port map (
   41:        clk => clk,
   42:        enable => '1', 
   43:        reset => reset,
   44:        count => nine_count,
   45:        overflow => nine_overflow
   46:      );
   47:  
   48:  --Zehnerzähler (Zählt von 0 bis 5)
   49:      high_counter: GenericCounter123
   50:      generic map (
   51:          Count_max => 5  -- Zählt von 0 bis 5 (Zehnerstelle)
   52:      )
   53:      port map (
   54:        clk => clk,
   55:        enable => nine_overflow,
   56:        reset => reset,
   57:        count => five_count,
   58:        overflow => five_overflow
   59:      );
   60:  
   61:  --Zuordnung der Ausgänge
   62:      count_1 <= nine_count;  -- Einerstellen
   63:      count_10 <= five_count;  -- Zehnerstellen
   64:  end architecture rtl;
   65:  

Code, Programmiersprache

(PHP-Script) Wieso funktioniert das einmal und einmal nicht?

Hab mal eine Frage zu einer Formular-PHP-aus-einer-json-Datei-auslese-und-wieder-eintrag Funktion, die ich versuche genauer zu verstehen. Genauer gesagt komm ich da an einer Stelle nicht weiter (weil sich Teile der Funktion scheinbar komplett willkürlich verhält!)

Also wenn ich in PHP eine Funktion in der Struktur hier habe:

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $params = [
   "p1" => isset($_POST['p1']) ? $_POST['p1'] : null,
   "p2" => isset($_POST['p2']) ? $_POST['p2'] : null,
   "p3" => isset($_POST['p3']) ? $_POST['p3'] : null,
       "p4" => isset($_POST['p4']) ? $_POST['p4'] : null,
   // A_settings
       "P5" => [
           "SP1" => $_POST['P1'],
           "SP2" => $_POST['P2'],
       ],
   ];

und der Inhalt der auszulesenden json Datei so aussieht:

{
   "p1": "antwort1",
   "p2": "antwort2",
   "p3": "antwort3",
   "p4": "antwort4",
   "self": {
       "P5": {
           "SP1": antwort5,
           "SP2": antwort6
       }
   }
}

klappt scheinbar alles hervorragend. Die Parameter werden gefunden und nach dem Absenden des Formulars korrekt überschrieben.

Wenn ich allerdings wie im folgenden Beispiel etwas mehr Parameter hinzufüge wie in dieser Struktur hier und für die Benennung etwas längere Namenschemen verwende:

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $params = [
      /// calculation nr1:
      "Self.P1" => isset($_POST['Self.P1']) ? $_POST['Self.P1'] : null,
      "Self.P2" => isset($_POST['Self.P2']) ? $_POST['Self.P2'] : null,
      "Self.P3" => isset($_POST['Self.P3']) ? $_POST['Self.P3'] : null,
      "Self.P4" => isset($_POST['Self.P4']) ? $_POST['Self.P4'] : null,
      .....
      "Self.P18" => isset($_POST['Self.P18']) ? $_POST['Self.P18'] : null,
      "Self.P19" => isset($_POST['Self.P19']) ? $_POST['Self.P19'] : null,
      "Self.P20" => isset($_POST['Self.P20']) ? $_POST['Self.P20'] : null,
      "Self.P21" => isset($_POST['Self.P21']) ? $_POST['Self.P21'] : null,
      ///
    // A_settings
       "self.A_settings" => [
           "w1" => $_POST['w1'],
           "w2" => $_POST['w2'],
       ],
      // B_settings
       "self.B_settings_2" => [
           "w3" => $_POST['w3'],
           "w4" => $_POST['w4'],
       ],

sieht die json-Datei nach dem Absenden für die ersten einfachen Parameter plötzlich so aus:

{
   "Self.P1": null,
   "Self.P2": null,
   "Self.P3": null,
   .....
    "Self.P21": null,

Nur die verschachtelten Parameter, die danach kommen:

"self.A_settings": {
       "w1": "Antwort1",
       "w2": "Antwort2"
   },
   "self.B_settings_2": {
       "w3": "Antwort3",
       "w4": "Antwort4"
   },

werden nach wie vor korrekt in die Datei geschrieben! 

Weiß einer oder hat eine Theorie wieso das eine problemlos funktioniert und bei der anderen Variante plötzlich systematisch alle einfachen Parameter (also Self.P1-21) den Wert "null" zurückgeben? 

Internet, Webseite, Formular, Code, PHP, Programmiersprache, Webentwicklung, Parameter

Snake Game HTML Score?

Ich will in meinem Snake Game: (Hier der Code)

Einen Score einbauen (ein Food = + ein Score) Kann mir jemand helfen?

//board
var blockSize = 25;
var rows = 20;
var cols = 20;
var board;
var context; 

//snake head
var snakeX = blockSize * 5;
var snakeY = blockSize * 5;

var velocityX = 0;
var velocityY = 0;

var snakeBody = [];

//food
var foodX;
var foodY;

var gameOver = false;

window.onload = function() {
    board = document.getElementById("board");
    board.height = rows * blockSize;
    board.width = cols * blockSize;
    context = board.getContext("2d"); //used for drawing on the board

    placeFood();
    document.addEventListener("keyup", changeDirection);
    // update();
    setInterval(update, 1000/10); //100 milliseconds
}

function update() {
    if (gameOver) {
        return;
    }

    context.fillStyle="black";
    context.fillRect(0, 0, board.width, board.height);

    context.fillStyle="red";
    context.fillRect(foodX, foodY, blockSize, blockSize);

    if (snakeX == foodX && snakeY == foodY) {
        snakeBody.push([foodX, foodY]);
        placeFood();
    }

    for (let i = snakeBody.length-1; i > 0; i--) {
        snakeBody[i] = snakeBody[i-1];
    }
    if (snakeBody.length) {
        snakeBody[0] = [snakeX, snakeY];
    }

    context.fillStyle="lime";
    snakeX += velocityX * blockSize;
    snakeY += velocityY * blockSize;
    context.fillRect(snakeX, snakeY, blockSize, blockSize);
    for (let i = 0; i < snakeBody.length; i++) {
        context.fillRect(snakeBody[i][0], snakeBody[i][1], blockSize, blockSize);
    }

    //game over conditions
    if (snakeX < 0 || snakeX > cols*blockSize || snakeY < 0 || snakeY > rows*blockSize) {
        gameOver = true;
        alert("Game Over");
    }

    for (let i = 0; i < snakeBody.length; i++) {
        if (snakeX == snakeBody[i][0] && snakeY == snakeBody[i][1]) {
            gameOver = true;
            alert("Game Over");
        }
    }
}

function changeDirection(e) {
    if (e.code == "ArrowUp" && velocityY != 1) {
        velocityX = 0;
        velocityY = -1;
    }
    else if (e.code == "ArrowDown" && velocityY != -1) {
        velocityX = 0;
        velocityY = 1;
    }
    else if (e.code == "ArrowLeft" && velocityX != 1) {
        velocityX = -1;
        velocityY = 0;
    }
    else if (e.code == "ArrowRight" && velocityX != -1) {
        velocityX = 1;
        velocityY = 0;
    }
}


function placeFood() {
    //(0-1) * cols -> (0-19.9999) -> (0-19) * 25
    foodX = Math.floor(Math.random() * cols) * blockSize;
    foodY = Math.floor(Math.random() * rows) * blockSize;
}
HTML, Webseite, CSS, JavaScript, Code, Programmiersprache, Webentwicklung

Meistgelesene Beiträge zum Thema Programmiersprache