C++ Questions and Answers

Solve problems and approach solutions. Just ask and lurkers wi...
Dec 7, 2022 21:15
Add that where though? My confusion is that I'm not explicitly using clang at any point, so I don't know where VSC is pulling it from, so I don't know how to change the apparent VSC invocation
Dec 7, 2022 21:04
@nwp Is there a way to disable this behavior?
Dec 7, 2022 21:04
Interestingly, the clang warnings only seem to appear when I have a -M flag in my CXXFLAGS
Dec 7, 2022 20:49
this is what I see ^
Dec 7, 2022 20:48
Dec 7, 2022 20:47
What do you mean? Pressing F5 just shows a bunch of errors for me because the compile invocation is missing important things
Dec 7, 2022 20:42
I have a c_cpp_settings.json in a .vscode directory in my project that seems to reference a compiler path to /usr/bin/clang, but if I change that to g++, nothing changes. I'm not really sure if this JSON plays a role in this issue
Dec 7, 2022 20:40
If I'm using g++ as my compiler in VSCode, why might I be seeing clang warnings when I run make?
Dec 5, 2022 08:48
Nevermind, this (stackoverflow.com/questions/16262344/…) answers my question
Dec 5, 2022 08:44
How could I make a dependency in a makefile refer to the name of the target? For example for helloworld : helloworld.cpp, I want something like helloworld : [email protected], but doing that evaluates the $@ to nothing
Nov 26, 2022 02:10
Also, I noticed the last question I asked here got moved to another room more suited for questions, but I do not remember how to get there. Sorry in advance, whoever moves this conversation to the other room
Nov 26, 2022 02:08
My current best idea is to make a logger object in the constructor of the class in B that points to the same log file as A, but that seems ad hoc and I'm not sure if it will overwrite what is written by A. Any ideas?
Nov 26, 2022 02:08
Hey guys, how might I make a logger (through spdlog) that works across multiple files? Meaning, I have one .cpp (call it A) with the main function, but I want to log a lot of what's happening in another .cpp (call it B) file that the main one #includes into the main's log output.
Nov 17, 2022 13:08
Thanks!
Nov 17, 2022 13:08
oops, i forgot the `, someObject)`

Ah, I see, that makes more sense
Nov 17, 2022 13:01
Hey guys, sorry if this is a braindead question, I'm kinda new to cpp. According to this question (stackoverflow.com/questions/19215027/…), one can use std::find(begin(myvec), end(myvec) != end(myvec) to check if an iterable contains a specific element. But what if the element I'm looking for is actually the last element? Won't it get ignored by this approach?
 

Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Oct 3, 2022 20:24
@Kevin That just might work. Thanks for the suggestion!
Oct 3, 2022 20:09
@0x263A Yes but the only method potentially useful there to my use case is Joystick.get_button, which does the same thing my current implementation does
Oct 3, 2022 20:06
@Code-Apprentice Do you know of any framework in particular that handles events like this? I may consider switching to it if this gets too hairy
Oct 3, 2022 20:04
oh boy
Oct 3, 2022 20:01
Perhaps the real docs and not the source code would be more helpful: psychopy.org/api/hardware/joystick.html
Oct 3, 2022 20:00
Here are the docs for psychopy.hardware.Joystick: psychopy.org/_modules/psychopy/hardware/joystick.html#Joystick. I haven't checked pygame's docs but so far I see no such implementation
Oct 3, 2022 19:59
Sorry if it's dummy easy logic but I keep tripping myself up over it
Oct 3, 2022 19:58
then turns off for the rest of the frames that my finger is down.
Oct 3, 2022 19:58
Hey guys, how might I go about making some kind of switch to detect gamepad button presses? I'm using psychopy's Joystick class, which uses pygame. I have a method to detect when a button is pressed, but the problem is it detects the press on every frame that I have my finger down (~15-20 frames per button press). I need some kind of "switch" that turns on on the first detected button press frame, does all the logic associated with the press,...
Aug 11, 2022 14:36
@Kevin I feel like making a class just so I can make one variable persist out of one function's scope is a little overkill, but I see where you're coming from
Aug 11, 2022 14:05
I guess I can work my logic such that it returns the last value as well, then pass that back into the function on the next run. That seems to be the most straightforward approach in my use case. Thanks for the speedy replies everyone
Aug 11, 2022 13:55
Let's say I need certain variables that are used (but not directly output by return) in a function to persist after the function is done running. I need this because the variables value in the previous run of the function determine to some extent the value of the variable on the next run through. Is there any way to encapsulate this kind of functionality without using global?
Aug 5, 2022 15:15
Thanks for the help once again @AndrasDeak--СлаваУкраїні, I got it working (except for an infinite loop in the code now that rand_streambit is never not in plus_or_minus_two_off after a few runs through the loop. I can fix this myself though). The guys active and helpful in this chat are doing the lord's work
Aug 5, 2022 15:09
answered my own question ^
Aug 5, 2022 15:01
as in [1, 2, 3, 4, 5, 6] not [[1, 2, 3], [4, 5, 6]]
Aug 5, 2022 14:58
it would need to be a list of all the ranges together for that if to work as expected
Aug 5, 2022 14:57
Ah yes I see. in line 21
Aug 5, 2022 14:54
Wishful thinking i suppose :P
Aug 5, 2022 14:52
I was under the impression that something like [range(1, 4)] would expand to [[1, 2, 3]], but I'm not sure where I got that idea from. What do you mean by "flat list of indices"
Aug 5, 2022 14:50
OIC
Aug 5, 2022 14:49
Basically, the T's that are chosen are still within 2 streambits of other T's. Why is this, if I explicitly check if they're in a +-2 range of the other previously chosen T's
Aug 5, 2022 14:48
This time I'll go ahead and post the pastebin first in case anyone can help from just my comments: pastebin.com/UcbwPWTq
Jul 30, 2022 20:40
Or is implementing an event-based approach myself simpler than I'm imagining it to be
Jul 30, 2022 20:39
@Aran-Fey though this works using the keyboard library, I've just discovered that psychopy has no analog to on_press_key, so I can't use an event-based approach like this. Maybe I can get rid of psychopy's keyboard in the program in favor of this approach?
Jul 30, 2022 20:16
@Aran-Fey hmm this looks promising. I considered using a callback but wasn't quite sure how I would implement it. I will try this out
Jul 30, 2022 20:11
@NordineLotfi it's the least I can do if I'm asking others for help haha
Jul 30, 2022 20:10
@AndrasDeak--СлаваУкраїні isn't that taken care of by the inner if? rt, and therefore the log message, is related to if "T" in streambit by start_time.
Jul 30, 2022 20:06
"can you detail "procing" here?" by procing I mean the if statement evaluates to true on each pass through the loop
Jul 30, 2022 20:05
time.sleep will hang the program for the duration of the sleep, won't it? I need the program to listen for a keypress for the entire duration of the experiment
Jul 30, 2022 20:04
"When you press a button it takes a while for it to register as unpressed, and until then you have a busy loop constantly hammering that if".
That's what I was thinking, but the keypress is logged over a timespan much larger than what a release time should be for just a press
Jul 30, 2022 20:02
If you look at MCVE.log, it seems that it outputs to the log file every few fractions of a ms
Jul 30, 2022 20:01
My question, then, is why does this if statement at line 38 keep procing even though the t press is only happening once? Shouldn't the code register the t press, run through the if statement, then be done with it until the next t press?
Jul 30, 2022 20:00
I'm not sure since only one responded and they couldn't install psychopy, so I was going to reiterate my issue here
Jul 30, 2022 19:58