• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

storage in c++

foxkbt

Member
Joined
Sep 29, 2009
Messages
290
Reaction score
7
Location
Salvador
how can i return a storage value in weapons.cpp function?
i try to get like this
Code:
int32_t attackValue = player->getStorage(897);

i use 0.3.6pl version of tfs
 
Last edited:
Code:
  int32_t value;
  if (player->getStorageValue(897, value)) {
    // storage exists
  } else {
    // storage doesn't exist
  }
 
thx man
but it dosent work
i try to compile and have a error
=/
the function that i change is
Code:
bool Weapon::useFist(Player* player, Creature* target)
 
i will try again to see the error
but now i'm compiling
i try like that
Code:
std::string value;
    if(!getStorage(897, value))
    int32_t attackValue = value;

@edit
the error
Code:
'class player' has no member named 'getStorageValue'

i guess you don understand what i want
i need to turn the "attackValue" equal to the value of storage
you know?
 
Last edited:
i will try again to see the error
but now i'm compiling
i try like that
Code:
std::string value;
    if(!getStorage(897, value))
    int32_t attackValue = value;

@edit
the error
Code:
'class player' has no member named 'getStorageValue'

i guess you don understand what i want
i need to turn the "attackValue" equal to the value of storage
you know?

I don't know which distro you're using, but from std::string type of variable value I am guessing that it's 0.3.6pl1. I'll try to help. Try something like that:
Code:
int32_t attackValue = 0;
std::string value;
player->getStorage(897, value);
if (value != "-1") {
     attackValue = atoi(value.c_str());
}
 
really thx @djseban
works perfectly
so...
you can explain to me how this work
i really like to understand better c++
--edit
yes i use 0.3.6pl
Sure,
In 0.3.6pl1 function getStorage has 2 parameters - first is number of storage value (in this case 897), in second parameter you have to specify in which variable this storage should be stored (in this case variable named "value"). If specified storage value is empty, then function getStorage is storing "-1" in our std::string, otherwise it's storing storage value which is stored in 897. Now about function atoi - since 0.3.6pl1 uses std::string as getStorage second parameter, it's not possible to simply attribute variable "value" to "attackValue" (which is int32_t), you have to cast (or in more simple word, convert) it to numerical format. So atoi is a good tool for that.

My best,
djseban
 
Last edited:
Back
Top