I've been working on a simple map editor tool for a game project in pygame. Right now I'm trying to have the program load all the images from a specific folder when it launches. For each image I create a file in a list, and make that into a custom class object. It is assigned a .fileImage value when I add it as a class object.
The error: Couldn't open E:\Pygame Engine Test\Assets\\Blocks\coldstoneWideBrick.png
I only don't understand this error because I've tried debugging the problem for a while now and it makes no sense.
When I load in the image I do this:
class editorBlocks:
def __init__(self, Image, Name, Type):
self.editName = Name
self.fileImage = pygame.image.load(blockDir + Image).convert()
self.obType = Type
If I have the program enter "coldstoneWideBrick.png" as the Image value for the class, it returns the above error. I've tried printing Image when I input it and get it "coldstoneWideBrick.png". However, if I replace the line that loads the image with this:
self.fileImage = pygame.image.load(blockDir + "coldstoneWideBrick.png").convert()
It loads the image without error. Why is it that it only has difficulty when I have it use the Image input, even though the input has an identical value?
After some further review of the problem, I noticed that when i printed in the value there was a blank line after it every time.
I was able to fix it by changing how I loaded in the image value (it was loaded from a file before put into a class.) Sorry for making such a simple mistake and thanks for your time!
Related
I've been making a simple app in C++/wxWidgets that just has a catalog of Garfield comix from the Internet, without the annoying ads and offers. (Don't ask me how I got access to the PNG files of each comic in the first place, because my name already explains that)
Anyway, I'm trying to make a static text with a specific font (in my case, that would be Tahoma size 8. I'm going to make it bold but for sake of simplicity I haven't done it yet). I use the following line of code to import it from the Windows internal font catalog:
wxFont *CC_FONT_Tahoma_Bold(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Tahoma"), wxFONTENCODING_DEFAULT);
but whenever I try that it just fails and gives the following error message (I'm using mingw-w64 8.1.0 if that helps):
error: cannot convert 'wxFontEncoding' to 'wxFont*' in initialization
I have no idea what this means and I have tried to change the font encoding to every possible value, but still no progress. Also, I am creating the font in the App's OnInit function. I have also tried to put it in a different function. Please help.
Turns out, I just made a silly mistake. 🤣🤪
The real code I should have used is:
wxFont *CC_FONT_Tahoma_Bold = new wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Tahoma"), wxFONTENCODING_DEFAULT);
I am developing a media player using vlc-qt I wanted to know how can I identify that my player contains a video or not.
For example
m_player=new VlcMediaPlayer(m_instance);
m_media= new VlcMedia("",m_instance);
m_player->open(m_media);
m_player->play()
As you can see here my m_media is initialized with no video url so how can I check whether my m_media contains any video or not.
I wanted to know this because so that in my player i will control play/stop button.
Solution
After opening the media use VlcMediaPlayer::video to retrieve the video object and check if it is valid, i.e. not a nullptr.
Example
Here is an example I wrote for you to demonstrate a possible implementation of the proposed solution:
m_player = new VlcMediaPlayer(m_instance);
m_media = new VlcMedia("", m_instance);
m_player->open(m_media);
if (m_player->video())
m_player->play();
According to VlcMedia source, the string you give to the class can be retrieved using the getter VlcMedia::currentLocation(). From that string, you can use QFile::exists() to check if the file path exists.
I am trying to code a gui that is dynamically assigned. I have four teams. I am getting stuck at a certain point. I want to make a function that, when a player joins the game, checks if the other teams have already scored to update their labels. It looks like this:
local function updateAllLabelsLateArrival(redPoints, bluePoints, yellowPoints, greenPoints)
game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyRedTeam.Points.Text = redPoints
game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyBlueTeam.Points.Text = bluePoints
game.Players.LocalPlayer.PlayerGui.ScreenGui.NewYellerTeam.Points.Text = yellowPoints
game.Players.LocalPlayer.PlayerGui.ScreenGui.LimeGreenTeam.Points.Text = greenPoints
end
The function is remotely triggered from a server-side script when a player joins. The problem I have is that not all four labels might exist. Suppose a green team player joins in when there is only a red team player already playing. It will come back with the error
ReallyBlueTeam is not a valid member of ScreenGui
I thought wrapping each line in an if statement to check if the label exists, like so:
if game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyRedTeam then game.Players.LocalPlayer.PlayerGui.ScreenGui.ReallyRedTeam.Points.Text = redPoints end
But this is giving the same error. So my question is, how do I check that a label has been created before updating the points? thanks
Assuming this is a localcsript, you can use WaitForChild() which will yield until the label has been created!
game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("ReallyRedTeam"):WaitForChild("Points").Text = redPoints
More information about WaitForChild here!
Alternatively, if you don't know for definite they will be created, you can use FindFirstChild. This won't yield.
if game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild("ReallyRedTeam") then
print("it exists")
end
More information about FindFirstChild here!
Hope that helps!
If you want them all on one line each then the best to use would be FindFirstChild() as #jjwood1600 has said. I would also recommend making use of a variable to shorten your GUI paths as you can see below:
local function updateAllLabelsLateArrival(redPoints, bluePoints, yellowPoints, greenPoints)
local userGui = game.Players.LocalPlayer.PlayerGui.ScreenGui
if userGui:FindFirstChild("ReallyRedTeam") then userGui.ReallyRedTeam.Points.Text = redPoints end
if userGui:FindFirstChild("ReallyBlueTeam") then userGui.ReallyBlueTeam.Points.Text = bluePoints end
if userGui:FindFirstChild("NewYellerTeam") then userGui.NewYellerTeam.Points.Text = yellowPoints end
if userGui:FindFirstChild("LimeGreenTeam") then userGui.LimeGreenTeam.Points.Text = greenPoints end
end
In normal Lua you can indeed do the if statements the way you did where you don't use FindFirstChild but Roblox's own version RBX.Lua doesn't.
I'm trying to load a model trained in Python into C++ and classify some data from a CSV. I found this tutorial:
https://medium.com/#hamedmp/exporting-trained-tensorflow-models-to-c-the-right-way-cf24b609d183#.3bmbyvby0
Which lead me to this piece of example code:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/label_image/main.cc
Which is looking very hopeful for me. However, the data I want to load is in a CSV, and not an image file, so I'm trying to rewrite the ReadTensorFromImageFile function. I was able to find a class DecodeCSV, but it's a little different than the DecodePNG and DecodeJpeg classes in the example code, and I end up with an OutputList instead of and Output. Using the [] operator on the list seems to crash my program. If anyone happens to know how to deal with this, it would be greatly appreciated. He are the relevant changes to the code:
// inside ReadTensorFromText
Output image_reader;
std::initializer_list<Input>* x = new std::initializer_list<Input>;
::tensorflow::ops::InputList defaults = ::tensorflow::ops::InputList(*x);
OutputList image_read_list;
image_read_list = DecodeCSV(root.WithOpName("csv_reader"), file_reader, defaults).output;
// Now cast the image data to float so we can do normal math on it.
// image_read_list.at(0) crashes the executable.
auto float_caster =
Cast(root.WithOpName("float_caster"), image_read_list.at(0), tensorflow::DT_FLOAT);
I need to have two IconListView in same form. I created a second class for displaying the second listview but while using the AddControl() in the second class it shows an 'undeclared identifier error AddControl'. While the same code works if AddControl() is used in Form class, but my application requires me to use AddControl() in the second class itself. What change should be added to make it usable.
__pIconListView = new IconListView();
result r=__pIconListView->Construct(Rectangle(0,300, 600, 300),Dimension(200,200), ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL);
__pIconListView->SetItemProvider(*this);
__pIconListView->AddIconListViewItemEventListener(*this);
r=AddControl(__pIconListView);
Made some changes in the code.
And the above code is given in the second class and the AddControl() is in red color meaning its valid. But soon after executing the code, when the execution reaches the AddControl(__pIconListView) the program crashes. The Log says 'Construct should be called before use'. But the above Construct() doesn't make any errors it works fine, I checked the log. So where is this bug comming from!
The GetClientAreaBounds() also hits error.
I found a solution by using AddControl(secondclassObject) in the initial class itself. But with an over head of checking each second whether the required images for the iconlistview has been completely fetched!
But still not found a way to use AddControl() in the second class.