Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: expected an expression  (Read 3765 times)

0 Members and 1 Guest are viewing this topic.

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
expected an expression
« on: April 15, 2020, 03:07:43 pm »
When i try to run this code it gives me an error:

expected an expression

(sorry for the bad english)

#include <iostream>
#include <SFML/Graphics.hpp>



using namespace sf;

int width = 1024;
int height = 768;
int roadW = 2000;
int segL = 200; //segment lenght
float camD = 0.84;//camera depth

struct Line
{
        float x, y, z; //pokemon reference & 3d center of line
        float X, Y, W; //screen coord
        float scale;

        Line() { x = y = z = 0; }

        //from world to screen coordinates
        void project(int camX, int camY, int camZ)
        {
                scale = camD / (z - camZ);
                X = (1 + scale * (x - camX)) * width / 2;
                Y = (1 - scale * (y - camY)) * height / 2;
                W = scale * roadW * width / 2;
        }
};

void drawQuad(RenderWindow& w, Color c, int x1, int y1, int w1, int x2, int y2, int w2)
{
        ConvexShape shape(4);
        shape.setFillColor(c);
        shape.setPoint(0, Vector2f(x1-w1,y1));
        shape.setPoint(1, Vector2f(x2-w2,y2));
        shape.setPoint(2, Vector2f(x2+w2,y2));
        shape.setPoint(3, Vector2f(x1+w1,y1));
        w.draw(shape);


}

int main()
{

        RenderWindow app(VideoMode(width, height), "Outrun Racing!");
        app.setFramerateLimit(60);

        std::vector<Line> lines;

        for (int i = 0; i < 1600; i++)
        {
                Line line;
                line.z = i * segL;

                lines.push_back(line);
        }

        int N = lines.size();

        while (app.isOpen())
        {
                Event e;
                while (app.pollEvent(e))
                {
                        if (e.type == Event::Closed)
                                app.close();   
                }
                app.clear();
               
                for (int n = 0; n < 300; n++)
                {
                        Line &l = lines[n % N];
                        l.project(0, 1500, 0);

                        Color grass = (n / 3) % 2 ? Color(16, 200, 16) : Color(0, 154, 0);
                        Color rumble = (n / 3) % 2 ? Color(225, 225, 225) : Color(0, 0, 0);
                        Color road = (n / 3) % 2 ? Color(107,107, 107) : Color(105, 105, 105);

                        Line p = lines[(n-1)%N];
                        drawQuad(app, grass, 0, p.Y, width, 0, l.Y, width);
                        drawQuad(app, rumble, p.X, p.Y, p.W * 1.2, l.X, l.Y, l.W * 1.2);
                        drawQuad(app, road, p.X, p.Y, ,p.x,p.z,p.W*1.2);
                }

                app.display();
        }
        return 0;
}
« Last Edit: April 15, 2020, 09:20:00 pm by P1T0 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: expected an expression
« Reply #1 on: April 15, 2020, 04:46:45 pm »
expected an expression is normal C++ compiler that has nothing to do with SFML and you can find tons of answer on the internet on what the cause might be or how to solve it.

Where does the error occur exactly?
At best, post the full error and not just part of it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: expected an expression
« Reply #2 on: April 15, 2020, 06:33:26 pm »
The error is changed, it gives me Error E0018 expected ')',and I don't understand why, since I put the parenthesis on it, I don't know this library and I'm in trouble.
There's the line of code:
drawQuad(app, road,p.x,p.y,p.z p.X, p.Y, ,p.W);

I'm programming with visual studio 2019
« Last Edit: April 15, 2020, 06:40:38 pm by P1T0 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: expected an expression
« Reply #3 on: April 15, 2020, 07:48:24 pm »
p.z p.X
A missing comma.
Laurent Gomila - SFML developer

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: expected an expression
« Reply #4 on: April 15, 2020, 09:18:47 pm »
Thanks a lot, but when i try to compile it opens a white window gives me an error :
Line 1501
Expression: vector subscript out of range


(sorry for the disturbance, but I'm new on this forum and on SFML in general, and sorry for the bad English)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: expected an expression
« Reply #5 on: April 15, 2020, 10:15:17 pm »
That's an assert triggered by vector::operator[] when the given index is greater than the size of the vector. Inspect the call stack to find out which line of your code triggers the assert.

You should take the time to learn and practice C++ properly (for example: with such a detailed error message you would have found the problem easily by searching a little bit by yourself). We can't teach you this complex language on the SFML forums ;)
Laurent Gomila - SFML developer

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: expected an expression
« Reply #6 on: April 16, 2020, 01:05:15 pm »
Thanks! ;D :D :)