#i want to make something like an inventory

43 messages · Page 1 of 1 (latest)

weary harbor
#

i want to make something like an inventory that can hold objects like takeHeal and acces them at every encounter in dungeonAttack

flat galleonBOT
#

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.

pure raven
weary harbor
#

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

pure raven
#

what have you tried so far

weary harbor
#

i made a class where i tried to store takeHeal but it doesn't work

pure raven
#

what doesn't work

weary harbor
#

it says use of undeclared identifier 'takeHeal';

clear sigil
#

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!

weary harbor
#

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?

clear sigil
#

Object like takeHeal - one object? Many objects? What is takeHeal? Is it a type? What the objects stored in inventory have in common?

weary harbor
#

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

clear sigil
#

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

clear sigil
#

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

weary harbor
#

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

weary harbor
clear sigil
#

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{}()

weary harbor
#

so,should i only use random_device{}()?

clear sigil
#

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 ^^"

weary harbor
#

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

flat galleonBOT
#

@weary harbor Has your question been resolved? If so, type !solved :)

clear sigil
#

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

weary harbor
#

sso,shhould i leave this project till i understand better these things?

clear sigil
#

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

weary harbor
#

all of the items do the same thing,add or subtract character's health and do damage to the monsters