-1

Hi i'm writing a basic tetris with ascii output

and I have a Block Object that I want to move around

How would I change the Character at a certain Position in my Field from my method?

but VisualStudio tells me

1>------ Build started: Project: Tetris, Configuration: Debug Win32 ------
1>Tetris.cpp
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(48): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(49): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(50): error C2108: subscript is not of integral type
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(91): warning C4305: '+=': truncation from 'double' to 'float'
1>Done building project "Tetris.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

code:

#include <iostream>

using namespace std;

int main()
{

const int FieldY = 20;
const int FieldX = 11;

char TetrisField[FieldY][FieldX] =
{
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
    "__________",
};

class Block {
public:
    float posX;
    float posY;
    char Character = 'A';

    void setPos( int x, int y)
    {
        posX = x;
        posY = y;
        TetrisField[posY][posX] = Character;
    };
};



while (true)
{
    Block B1;
    B1.setPos(0, 5);

    for (int n = 0; n < FieldY; n = n + 1)
    {
        cout << TetrisField[n][0] << TetrisField[n][1] << TetrisField[n][2] << TetrisField[n][3] << TetrisField[n][4]
            << TetrisField[n][5] << TetrisField[n][6] << TetrisField[n][7] << TetrisField[n][8] << TetrisField[n][9] << endl;

    };

};
return 0;
};

I know the output method is bad but thats just for testing

ok now im writig random stuff so that the stack overflow editor allowes me to post this question because apparently I have not jet written enaugh normal words, that are not Code. ah finally ;-)

thx

majorTom
  • 57
  • 6
  • 1
    While the design is questionable there's nothing obviously wrong with the code you provided. Can you please post [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)? – orhtej2 Oct 04 '17 at 07:15
  • 1
    Also, notice how you should first erase block from previous position before moving it. – orhtej2 Oct 04 '17 at 07:16
  • Please copy and paste the entire error message instead of retyping it. Use the Output window, not the Error List window. – molbdnilo Oct 04 '17 at 07:24
  • so now the question is in its final form – majorTom Oct 04 '17 at 07:42

1 Answers1

0

In TetrisField[posY][posX] posY and posX are float values. "subscript is not of integral type" indicates that you cannot index your array with them.

hrantzsch
  • 353
  • 2
  • 7
  • ahh im an idiot why do i keep making such mistakes Thank you – majorTom Oct 04 '17 at 07:45
  • happy to help. is you question answered? – hrantzsch Oct 04 '17 at 08:15
  • not really when i fixed that there is still my earlyer problem witch has to do with data access maybe? what does this tell you? e:\dateien\uni\c++\tetris\tetris\tetris.cpp(53): error C2326: 'void main::Block::setPos(float,float)': function cannot access 'TetrisField' – majorTom Oct 04 '17 at 12:01