#why are some commands not yellow?

109 messages · Page 1 of 1 (latest)

plain dawnBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#

@coral nova

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

finite pond
#

Do yourself a favor and make a function that can take a vector or array as a parameter, and flip the visibility of each item

#

Then you can reduce all of that down to like two lines of code

coral nova
#

that is a very good hint. i will we write the code to loops

finite pond
#

Do any of those functions work or does it have the same error for all of them?

coral nova
#

no its just this part:
the OnClick code goes like this:

if (Defense.isMouseOver(window) && Defense.onlcick_name == "Defense") {
WallSmallMk1.setVisibility(!WallSmallMk1);
WallSmallMk2.setVisibility(!WallSmallMk2);
WallSmallMk3.setVisibility(!WallSmallMk3);
WallSmallMk4.setVisibility(!WallSmallMk4);
WallSmallMk5.setVisibility(!WallSmallMk5);
. . .
}

all functions work but in this case i have a problem

finite pond
#

Are all of these objects of the same type or no?

#

And if they're different, do all of these objects have the .setVisibility() method in their class?

coral nova
#

yess

i solved the problem btw. in the create object file was "TurretSingleMK1" that causes the problem that "Turret Mk1" doestn exist

finite pond
#

Ah I see, nice

coral nova
finite pond
#

I can give you an idea of what it might look like, sure

coral nova
#

Thx

finite pond
#
void invertVisibility(std::vector<type> &vector) {
  for (auto &item : vector) {
    item.setVisibility(!item);
  }
}
#

Something like that

#

where type is the object type

#

And then you make a vector of the objects you want to flip, call that function, and pass it in

coral nova
#

Ok i will try

#

Ok now i have to code a loop which creates the button ....
Thats easy ...
i think

coral nova
finite pond
#

I would just create those manually, unless you need to create hundreds for example. If that's the case there's probably a better way to do it

#

But for now just create them manually, add them all to a vector (you can use std::push_back(), google if it need be), and then pass that vector into the function

#

If I do all the work for you you wouldn't learn anything, I would implore you to do what you can on your own and give it a try, and then ask again if you run into issues 🙂

coral nova
#

so you say that a loop which creates all the Mk versionen of the objects is stupid ?

#

I dont know whats incorrect here:

finite pond
#

What does the error say?

#

I'll give you a hint, check the type of the vector compared to the type of the object you're trying to insert into it

coral nova
#

This declaration has no storage class or type specifier.

#

i dont know which type my buttons are. think they are object class element or something like that. but i dont know hot to setup the vector correctly

fierce gyro
fierce gyro
coral nova
#

so it should be like:

std::vector<Button> buildDefense;

#

but the error is still there

finite pond
#

Yes

#

What is the error now?

coral nova
#

This declaration has no storage class or type specifier.

#

thats the error when I hover "buildDefense.push_back()"

tiny storm
coral nova
#

std::vector<Button> buildDefense;

Button WallSmallMk1 = Button("WallSmallMk1", "WallSmallMk1", 440, 25, 120, 25, "Wall Small Mk1", 15, false, wallsmallmk1Color);
Button WallSmallMk2 = Button("WallSmallMk2", "WallSmallMk2", 440, 50, 120, 25, "Wall Small Mk2", 15, false, wallsmallmk2Color);
Button WallSmallMk3 = Button("WallSmallMk3", "WallSmallMk3", 440, 75, 120, 25, "Wall Small Mk3", 15, false, wallsmallmk3Color);
Button WallSmallMk4 = Button("WallSmallMk4", "WallSmallMk4", 440, 100, 120, 25, "Wall Small Mk4", 15, false, wallsmallmk4Color);
Button WallSmallMk5 = Button("WallSmallMk5", "WallSmallMk5", 440, 125, 120, 25, "Wall Small MK5", 15, false, wallsmallmk5Color);
buildDefense.push_back(WallSmallMk1);
#

============
Like that ?

plain dawnBOT
fierce gyro
#
    std::vector<Button> buildDefense;

    Button WallSmallMk1 = Button("WallSmallMk1", "WallSmallMk1", 440, 25, 120, 25, "Wall Small Mk1", 15, false, wallsmallmk1Color);
    Button WallSmallMk2 = Button("WallSmallMk2", "WallSmallMk2", 440, 50, 120, 25, "Wall Small Mk2", 15, false, wallsmallmk2Color);
    Button WallSmallMk3 = Button("WallSmallMk3", "WallSmallMk3", 440, 75, 120, 25, "Wall Small Mk3", 15, false, wallsmallmk3Color);
    Button WallSmallMk4 = Button("WallSmallMk4", "WallSmallMk4", 440, 100, 120, 25, "Wall Small Mk4", 15, false, wallsmallmk4Color);
    Button WallSmallMk5 = Button("WallSmallMk5", "WallSmallMk5", 440, 125, 120, 25, "Wall Small MK5", 15, false, wallsmallmk5Color);
    buildDefense.push_back(WallSmallMk1);
#

You likely have the copy constructor deleted for Button, and .push_back performs a copy, which will fail if the copy constructor is deleted.

What you likely need is .emplace (even if it makes error messages somewhat gnarly if used incorrectly):

    std::vector<Button> buildDefense;

    buildDefense.emplace("WallSmallMk1", "WallSmallMk1", 440, 25, 120, 25, "Wall Small Mk1", 15, false, wallsmallmk1Color);
    buildDefense.emplace("WallSmallMk2", "WallSmallMk2", 440, 50, 120, 25, "Wall Small Mk2", 15, false, wallsmallmk2Color);
    buildDefense.emplace("WallSmallMk3", "WallSmallMk3", 440, 75, 120, 25, "Wall Small Mk3", 15, false, wallsmallmk3Color);
    buildDefense.emplace("WallSmallMk4", "WallSmallMk4", 440, 100, 120, 25, "Wall Small Mk4", 15, false, wallsmallmk4Color);
    buildDefense.emplace("WallSmallMk5", "WallSmallMk5", 440, 125, 120, 25, "Wall Small MK5", 15, false, wallsmallmk5Color);
coral nova
#

the error still exists

#

i tried:

buildDefense.emplace(WallSmallMk1);

fierce gyro
#

So the code would actually be:

    std::vector<Button> buildDefense;

    buildDefense.emplace_back("WallSmallMk1", "WallSmallMk1", 440, 25, 120, 25, "Wall Small Mk1", 15, false, wallsmallmk1Color);
    buildDefense.emplace_back("WallSmallMk2", "WallSmallMk2", 440, 50, 120, 25, "Wall Small Mk2", 15, false, wallsmallmk2Color);
    buildDefense.emplace_back("WallSmallMk3", "WallSmallMk3", 440, 75, 120, 25, "Wall Small Mk3", 15, false, wallsmallmk3Color);
    buildDefense.emplace_back("WallSmallMk4", "WallSmallMk4", 440, 100, 120, 25, "Wall Small Mk4", 15, false, wallsmallmk4Color);
    buildDefense.emplace_back("WallSmallMk5", "WallSmallMk5", 440, 125, 120, 25, "Wall Small MK5", 15, false, wallsmallmk5Color);
#

;compile cpp

#include <string>
#include <vector>

class Button {
public:
    Button(std::string a, std::string b, int c, int d, int e, int f, std::string g, int h, bool i) {};
};

int main(){
        std::vector<Button> buildDefense;

    buildDefense.emplace_back("WallSmallMk1", "WallSmallMk1", 440, 25, 120, 25, "Wall Small Mk1", 15, false);
    buildDefense.emplace_back("WallSmallMk2", "WallSmallMk2", 440, 50, 120, 25, "Wall Small Mk2", 15, false);
    buildDefense.emplace_back("WallSmallMk3", "WallSmallMk3", 440, 75, 120, 25, "Wall Small Mk3", 15, false);
    buildDefense.emplace_back("WallSmallMk4", "WallSmallMk4", 440, 100, 120, 25, "Wall Small Mk4", 15, false);
    buildDefense.emplace_back("WallSmallMk5", "WallSmallMk5", 440, 125, 120, 25, "Wall Small MK5", 15, false);
}
serene boughBOT
#
Compilation successful

No output.

coral nova
#

I tried this code lines. but even with .emplace_back the error is here

#

"This declaration has no storage class or type specifier."

there is something wrong with the vector definition

fierce gyro
coral nova
#

yes

fierce gyro
#

Then your Button's move constructor is likely deleted as well, which means that you need to use pointers, I would strongly suggest smart pointers, like std::unique_ptr:

#include <string>
#include <vector>
#include <memory>

class Button {
public:
    Button(std::string a, std::string b, int c, int d, int e, int f, std::string g, int h, bool i) {};

    // Delete the copy constructors, to make this behave as the OG Button likely does
    Button (const Button&) = delete;
    Button& operator= (const Button&) = delete;
};

int main(){
    std::vector<std::unique_ptr<Button>> buildDefense;

    buildDefense.emplace_back(std::make_unique<Button>("WallSmallMk1", "WallSmallMk1", 440, 25, 120, 25, "Wall Small Mk1", 15, false));
    buildDefense.emplace_back(std::make_unique<Button>("WallSmallMk2", "WallSmallMk2", 440, 50, 120, 25, "Wall Small Mk2", 15, false));
    buildDefense.emplace_back(std::make_unique<Button>("WallSmallMk3", "WallSmallMk3", 440, 75, 120, 25, "Wall Small Mk3", 15, false));
    buildDefense.emplace_back(std::make_unique<Button>("WallSmallMk4", "WallSmallMk4", 440, 100, 120, 25, "Wall Small Mk4", 15, false));
    buildDefense.emplace_back(std::make_unique<Button>("WallSmallMk5", "WallSmallMk5", 440, 125, 120, 25, "Wall Small MK5", 15, false));
}
serene boughBOT
#
Compilation successful

No output.

coral nova
#

im unsure how to change the class "Button" to use this methode

fierce gyro
#

The std::unique_ptr handles the copy/move as only it is moved, not the Button it's pointing to

std::vector has a limitation that it needs to move objects in the underlying array if it runs out of space, thus a move constructor is needed

coral nova
#

i chnage to line to:
std::vector<std::unique_ptr<Button>> buildDefense;

nothing changed at the "buildDefense.emplace_back" but the error ist thill there. I also wrote "#include<memory>"

fierce gyro
#

The easiest way to construct std::unique_ptr is to call the std::make_unique function, as I did in the emplace_back (in case you overlooked that, since it is in the midst of the code)

coral nova
fierce gyro
#

Can you try running a full compile, in case you aren't, since sometimes IDEs cache error messages

coral nova
#

done

#

i also read the error messages

#

it seems that the compiler tries to convert "Button" into a bool

#

that one of the error

fierce gyro
#

You probably need to share some more code in that case, since it seems that is rather weird behavior for the compiler to attempt

#

Also, what gui library are you using?

coral nova
#

SFML

#

currently im trying to correct the errors from the default code:
in this case i dont youse a vector to storage al the components.
With this setting I only have one error:
"onclick_name" is not part of the obj.

when the compiling of this methode works and the .exe file starts without any problems then i will go back and try to include the vertors

#

no way, the compiling was succssesful

#

but the .exe file closes itselfe after starting it

#

when the programm works without any problems, i will trie to include the vectors 🙂

coral nova
fierce gyro
coral nova
#

no, i double cliked the exe file

fierce gyro
#

Try running from CMD/Powershell, since that gives you an error message when your program exits with a fault

coral nova
#

what the cmd command to run a exe file ?

fierce gyro
coral nova
#

i did already

fierce gyro
#

Also I just noticed, since you're in VS, you can run using the Run/Debug button, this gives even better error info, since you can step through using the debugger

coral nova
#

done

#

I will copy the errors: cause i dont know what the errors mean:

1>ConsoleApplication1.obj : error LNK2019: Reference to unresolved external symbol ""__declspec(dllimport) public: __cdecl sf::Font::~Font(void)" (_imp??1Font@sf@@QEAA@XZ)" in function ""public: __cdecl Window::~Window(void)" (??1Window@@QEAA@XZ)".
1>ConsoleApplication1.obj : error LNK2019: Reference to unresolved external symbol ""__declspec(dllimport) public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (_imp??1RenderWindow@sf@@UEAA@XZ)" in function ""public: __cdecl Window::~Window(void)" (??1Window@@QEAA@XZ)".
1>ConsoleApplication1.obj : error LNK2019: Reference to unresolved external symbol ""public: __cdecl Window::Window(void)" (??0Window@@QEAA@XZ)" in function "main".
1>ConsoleApplication1.obj : error LNK2019: Reference to unresolved external symbol ""public: void __cdecl Window::create_objects(void)" (?create_objects@Window@@QEAAXXZ)" in function "main".
1>C:\Users\UsersIn\Documents\Visual Studio 2022\Projects\ConsoleApp1\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe : fatal error LNK1120: 4 unresolved externals
1>The creation of the project "ConsoleApplication1.vcxproj" is complete -- ERROR.
========== Build: 0 successful, 1 error, 0 current, 0 skipped ==========
========== Build completed at 10:06 and took 02:52,846 minutes ==========

fierce gyro
#

You likely forgot to add the dll for it to link to (which includes SFML)

mystic compass
#

@coral nova did you try turning off your pc

coral nova
#

no

mystic compass
#

Then look no further

fierce gyro
#

Also, since I have to go, if it's still not running:

  1. Run in VS (this will give you the option of both step-through using the breakpoints, as well as auto-stop when an error such as segfaults happens)
  2. Check if your exit condition is faulty, which would make the program exit (correctly for the computer, erroneously for your interpretation)
mystic compass
#

Also I see you’re using visual studio as your IDE I would recommend switching to Repl.it to get the full coding experience

fierce gyro
coral nova
#

i dont want to. setting vs up ind include cmake was very confusing

#

if you mean that I should add SFMl to the environment variables of windows, then I already did that the day before yesterday

fierce gyro
#

If you're using the templates/cmake, this should be done automatically, and the built libraries are under build/_deps/SFML-build/library

fierce gyro
coral nova
#

and i set this in the CMakeLists.txt file, right?

fierce gyro
mystic compass
#

Did you try adding this line in your cmake ?

#

Shoot wrong image

coral nova
fierce gyro
mystic compass
#

Sorry I didn’t realize roles where switched up I thought you were trolling since I saw you were an expert 😭😭

coral nova
#

i need a break from coding O.o

coral nova
#

!solved

plain dawnBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity