#i want to make something like an inventory
43 messages · Page 1 of 1 (latest)
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.
that sounds great! you should do that!
the problem is that idk how to do that
im a begginer,and idk how to use poineters,tempaltes or things like that that chatgpt tells me to use
what have you tried so far
i made a class where i tried to store takeHeal but it doesn't work
what doesn't work
it says use of undeclared identifier 'takeHeal';
That's not something we can help you by - post the snippet that causes the error and tell us what you'd like to achieve with it - then we can direct you!
i want to make an inventory that can hold object like takeHeal,but idk how to do that,do u have any suggestions that are not very advanced?
Object like takeHeal - one object? Many objects? What is takeHeal? Is it a type? What the objects stored in inventory have in common?
takeHeal is void type,objects that will be in the inventory will not have mych in common,i just think that if i put them all in one place it will be easier for me to access them
Some comments on your code:
CurrentCharacter does not make sense as a class. It's just Character/Dungeon.
modify is just an assignment, no need for a function
If they don't have anything in common why store them together?
I think they might have a lot in common. They might have a name, count (if you want to stack them), they can be used (?)
Your random number generation is really bad. For many reasons
yes,they can be used,i want to dispaly all of the elements in the invventory,but some of them may not be added yet,so i think that's easier to dispaly all of the elements in the inventory then to dispaly each,and if any other is added to modify that
ik,but idk what to do,i know that the best rng in the random library is mt19937
Yeah but that's not quite the problem here
The tutorials are bad for that, I don't blame you, I've seen the same in production code many times
The thing is, that each time you create a random device - so you open/register for some system service and then take one, truly random number from it
Then, you initialize massive rng - MT - with this one truly random number. Getting a number from random_device is costly, initializing an entire rng is usually even more costly.
Then, you use this massive, heavy rng to take one number from it using a distribution
A reminder, you already had a random number at the point you call random_device{}()
so,should i only use random_device{}()?
Not the greatest, but better than what you have rn
uniform_int_distribution nr(x,y);
return nr(std::random_device{});
}
Wait that won't work
std::random_device rd;
uniform_int_distribution nr(x,y);
return nr(rd);
}
Here
Sorry ^^"
ty,i corrected that,but i still dont know how to store these functions togheter(takeHeal and any other functions that i will make to use them inside dungeonAttack)
onee thing that all of these function will have in common is that they will be void,i think that's the best option
@weary harbor Has your question been resolved? If so, type !solved :)
Your functions right now do not work at all, are you aware of that?
First of all get rid of the Current classes, they are absolutely unnecessary
Then, the issue with your functions is that they take parameters "by value" - the parameters you take are copies within the function, you do not change the same element
You need to pass by reference to do it
Btw, you are trying to store together functions, not objects - that's a bit more tricky
sso,shhould i leave this project till i understand better these things?
Not necessarily, you can learn them writing this project!
Tell me a bit more about the items you want to have, what would they do etc
To figure out how to handle them
all of the items do the same thing,add or subtract character's health and do damage to the monsters