• 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!

C++ addAnimatedText

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
hello guys
i add this cod in player.cpp fuction
void Player::eek:nThink(uint32_t interval)
Lua:
                        char num[4];
        sprintf(num, "%d", 5-1);
        g_game.addAnimatedText(getPosition(), COLOR_YELLOW, num);
i need this cod work like
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, 4);
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, 3);
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, 2);
anyone can help
0.4
 
Solution
Yikes! error: ‘to_string’ is not a member of ‘std’ :O

in player.cpp add:
C++:
#include <sstream>

and change the function to this one:
C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    std::stringstream ss;
    ss << n;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, ss.str());
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, this, n-1)));
}
Not a cpp expert but is this what you want? an animated countdown?

C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, n-1)));
}

C++:
// ...
// Whereever you want to start sending the animated text ( in player.cpp )
uint32_t n = 5;
sendAnimatedNumbers(n);
 
Last edited:
Not a cpp expert but is this what you want? an animated countdown?

C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, n-1)));
}

C++:
// ...
// Whereever you want to start sending the animated text ( in player.cpp )
uint32_t n = 5;
sendAnimatedNumbers(n);
and in player.h
void sendAnimatedNumbers(uint32_t n);
?
 
Lua:
In file included from /usr/include/boost/bind/mem_fn.hpp:25:0,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/function/detail/prologue.hpp:18,
                 from /usr/include/boost/function.hpp:24,
                 from otpch.h:34,
                 from player.cpp:17:
/usr/include/boost/get_pointer.hpp:25:23: note: template<class T> T* boost::get_pointer(const std::auto_ptr<T>&)
/usr/include/boost/get_pointer.hpp:25:23: note:   template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
                 from /usr/include/boost/function/detail/prologue.hpp:18,
                 from /usr/include/boost/function.hpp:24,
                 from otpch.h:34,
                 from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note:   mismatched types ‘const std::auto_ptr<T>’ and ‘const unsigned int’
 
Lua:
In file included from /usr/include/boost/bind/mem_fn.hpp:25:0,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/function/detail/prologue.hpp:18,
                 from /usr/include/boost/function.hpp:24,
                 from otpch.h:34,
                 from player.cpp:17:
/usr/include/boost/get_pointer.hpp:25:23: note: template<class T> T* boost::get_pointer(const std::auto_ptr<T>&)
/usr/include/boost/get_pointer.hpp:25:23: note:   template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
                 from /usr/include/boost/function/detail/prologue.hpp:18,
                 from /usr/include/boost/function.hpp:24,
                 from otpch.h:34,
                 from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note:   mismatched types ‘const std::auto_ptr<T>’ and ‘const unsigned int’
is that all or do you see any error: messages?
 
is that all or do you see any error: messages?

player.cpp:3745:111: required from here
/usr/include/boost/bind/mem_fn.hpp:333:36: error: no matching function for call to ‘get_pointer(const unsigned int&)’
/usr/include/boost/bind/mem_fn.hpp:333:36: note: candidates are:
In file included from /usr/include/boost/function/function_base.hpp:29:0,
from /usr/include/boost/function/detail/prologue.hpp:17,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/ref.hpp:182:29: note: template<class T> T* boost::get_pointer(const boost::reference_wrapper<T>&)
/usr/include/boost/ref.hpp:182:29: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note: mismatched types ‘const boost::reference_wrapper<T>’ and ‘const unsigned int’
In file included from /usr/include/boost/bind/mem_fn.hpp:25:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/get_pointer.hpp:18:23: note: template<class T> T* boost::get_pointer(T*)
/usr/include/boost/get_pointer.hpp:18:23: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note: mismatched types ‘T*’ and ‘unsigned int’
In file included from /usr/include/boost/bind/mem_fn.hpp:25:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/get_pointer.hpp:25:23: note: template<class T> T* boost::get_pointer(const std::auto_ptr<T>&)
/usr/include/boost/get_pointer.hpp:25:23: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note: mismatched types ‘const std::auto_ptr<T>’ and ‘const unsigned int’
 
player.cpp:3745:111: required from here
/usr/include/boost/bind/mem_fn.hpp:333:36: error: no matching function for call to ‘get_pointer(const unsigned int&)’
/usr/include/boost/bind/mem_fn.hpp:333:36: note: candidates are:
In file included from /usr/include/boost/function/function_base.hpp:29:0,
from /usr/include/boost/function/detail/prologue.hpp:17,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/ref.hpp:182:29: note: template<class T> T* boost::get_pointer(const boost::reference_wrapper<T>&)
/usr/include/boost/ref.hpp:182:29: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note: mismatched types ‘const boost::reference_wrapper<T>’ and ‘const unsigned int’
In file included from /usr/include/boost/bind/mem_fn.hpp:25:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/get_pointer.hpp:18:23: note: template<class T> T* boost::get_pointer(T*)
/usr/include/boost/get_pointer.hpp:18:23: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note: mismatched types ‘T*’ and ‘unsigned int’
In file included from /usr/include/boost/bind/mem_fn.hpp:25:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/get_pointer.hpp:25:23: note: template<class T> T* boost::get_pointer(const std::auto_ptr<T>&)
/usr/include/boost/get_pointer.hpp:25:23: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/function/detail/prologue.hpp:18,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/boost/bind/mem_fn.hpp:333:36: note: mismatched types ‘const std::auto_ptr<T>’ and ‘const unsigned int’

try

C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, this, n-1)));
}
 
try

C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, this, n-1)));
}
error more than be4
 

player.cpp: In member function ‘void Player::sendAnimatedNumbers(uint32_t)’:
player.cpp:1940:58: error: invalid user-defined conversion from ‘uint32_t {aka unsigned int}’ to ‘const string& {aka const std::basic_string<char>&}’ [-fpermissive]
In file included from /usr/include/c++/4.7/string:55:0,
from /usr/include/c++/4.7/stdexcept:40,
from /usr/include/boost/function/function_base.hpp:14,
from /usr/include/boost/function/detail/prologue.hpp:17,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: note: candidate is: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] <near match>
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: note: no known conversion for argument 1 from ‘uint32_t {aka unsigned int}’ to ‘const char*’
player.cpp:1940:58: error: invalid conversion from ‘uint32_t {aka unsigned int}’ to ‘const char*’ [-fpermissive]
In file included from /usr/include/c++/4.7/string:55:0,
from /usr/include/c++/4.7/stdexcept:40,
from /usr/include/boost/function/function_base.hpp:14,
from /usr/include/boost/function/detail/prologue.hpp:17,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ [-fpermissive]
 
player.cpp: In member function ‘void Player::sendAnimatedNumbers(uint32_t)’:
player.cpp:1940:58: error: invalid user-defined conversion from ‘uint32_t {aka unsigned int}’ to ‘const string& {aka const std::basic_string<char>&}’ [-fpermissive]
In file included from /usr/include/c++/4.7/string:55:0,
from /usr/include/c++/4.7/stdexcept:40,
from /usr/include/boost/function/function_base.hpp:14,
from /usr/include/boost/function/detail/prologue.hpp:17,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: note: candidate is: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] <near match>
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: note: no known conversion for argument 1 from ‘uint32_t {aka unsigned int}’ to ‘const char*’
player.cpp:1940:58: error: invalid conversion from ‘uint32_t {aka unsigned int}’ to ‘const char*’ [-fpermissive]
In file included from /usr/include/c++/4.7/string:55:0,
from /usr/include/c++/4.7/stdexcept:40,
from /usr/include/boost/function/function_base.hpp:14,
from /usr/include/boost/function/detail/prologue.hpp:17,
from /usr/include/boost/function.hpp:24,
from otpch.h:34,
from player.cpp:17:
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ [-fpermissive]
pls show line 1940 in player.cpp
 
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
void addAnimatedText(const Position& pos, uint8_t textColor, const std::string& text);

addAnimatedText takes std::string as last parameter.

so try this ( inside the sendAnimatedNumbers function ):
change
C++:
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
to
C++:
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, std::to_string(n));
 
void addAnimatedText(const Position& pos, uint8_t textColor, const std::string& text);

addAnimatedText takes std::string as last parameter.

so try this ( inside the sendAnimatedNumbers function ):
change
C++:
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, n);
to
C++:
g_game.addAnimatedText(getPosition(), COLOR_YELLOW, std::to_string(n));
player.cpp: In member function ‘void Player::sendAnimatedNumbers(uint32_t)’:
player.cpp:1940:57: error: ‘to_string’ is not a member of ‘std’
player.cpp:1940:57: note: suggested alternatives:
In file included from /usr/include/boost/exception_ptr.hpp:9:0,
from /usr/include/boost/thread/future.hpp:14,
from /usr/include/boost/thread.hpp:24,
from otsystem.h:34,
from player.h:20,
from player.cpp:21:
/usr/include/boost/exception/detail/exception_ptr.hpp:482:5: note: ‘boost::to_string’
In file included from /usr/include/boost/exception/to_string_stub.hpp:15:0,
from /usr/include/boost/exception/info.hpp:16,
from /usr/include/boost/exception/detail/exception_ptr.hpp:20,
from /usr/include/boost/exception_ptr.hpp:9,
from /usr/include/boost/thread/future.hpp:14,
from /usr/include/boost/thread.hpp:24,
from otsystem.h:34,
from player.h:20,
from player.cpp:21:
/usr/include/boost/exception/to_string.hpp:26:65: note: ‘boost::to_string_detail::to_string’
player.cpp:1942:41: error: expected primary-expression before ‘,’ token
 
Yikes! error: ‘to_string’ is not a member of ‘std’ :O

in player.cpp add:
C++:
#include <sstream>

and change the function to this one:
C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    std::stringstream ss;
    ss << n;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, ss.str());
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, this, n-1)));
}
 
Solution
Yikes! error: ‘to_string’ is not a member of ‘std’ :O

in player.cpp add:
C++:
#include <sstream>

and change the function to this one:
C++:
void Player::sendAnimatedNumbers(uint32_t n) {
    if (n == 0)
        return;

    std::stringstream ss;
    ss << n;

    g_game.addAnimatedText(getPosition(), COLOR_YELLOW, ss.str());
    Scheduler::getInstance().addEvent(createSchedulerTask(1000, boost::bind(&Player::sendAnimatedNumbers, this, n-1)));
}
take my heart ♥️
 
Back
Top