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

Compiling General c++ error

swevaman

New Member
Joined
Jun 18, 2013
Messages
38
Reaction score
0
I tried to change
maxValue <<= 1;
to
maxValue <<= 1.2;

and got a few errors
In member function `virtual int32_t WeaponDistance::getWeaponDamage(const Player*, const Creature*, const Item*, bool) const':
invalid operands of types `int32_t' and `double' to binary `operator<<'
in evaluation of `operator<<=(int32_t, double)'

I think i know why it's happening, there's no string to tell my compiler that there's a decimal, but I don't know how to add one as I'm quite the c++ noob.

Any help appreciated.


Code:
int32_t WeaponDistance::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const
{
	int32_t attackValue = ammuAttackValue;
	if(item->getWeaponType() == WEAPON_AMMO){
		Item* bow = const_cast<Player*>(player)->getWeapon(true);
		if(bow){
			attackValue += bow->getAttack();
		}
	}

	int32_t attackSkill = player->getSkill(SKILL_DIST, SKILL_LEVEL);
	float attackFactor = player->getAttackFactor();
	int32_t maxValue = Weapons::getMaxDistanceWeaponDamage(attackSkill, attackValue, attackFactor);
			if(random_range(1, 100) <= g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
		     {  
			maxValue <<= 1.2;
			player->sendCriticalHit();
      }
 
the << operator shifts the bits by the number specificied.. so if the bits were 0110001.. the new bits 1100010.. shifted to one to the left or right depending if you use >> or <<
the <<= means to apply that to the left hand operator.. so basicly
maxValue <<= 1;
is the same as
maxValue = maxValue << 1;
that should multiply the value by 2.. is that the results your getting?
you can't shift bits over by a decimal value and that's why you have an error

you could do normal operations to maxValue tho.. try maxValue *= 1.2.. that will multi the maxValue by 1.2
 
"int32_t maxValue " is defined as an integer but then 1.2 is a floating value
Ahh that made sense.

How would I make it so I could make it 1.2?

How could I alter int32_5 maxValue to make it so it would accept a floating value, or a multiplied value such as 1 * 0.5?

- - - Updated - - -

you could do normal operations to maxValue tho.. try maxValue *= 1.2.. that will multi the maxValue by 1.2
[Warning] converting to `int32_t' from `double'
I used
maxValue *= 1.2;[/QUOTE]
 
Last edited:
Well I'm not really sure what the 32_t is, but i think its just to make the integers larger, so instead of using float you could just use double :
Code:
double maxValue = Weapons::getMaxDistanceWeaponDamage(attackSkill, attackValue, attackFactor);
 
the heart of your problem I explained.. the error has nothing to do with the opposing types.. c++ is not a type strict language
your going to get a warning.. because it forces rounding

if the max was 53
its giving an error because its assigning 63 to maxValue instead of 63.6, but since you don't care about rounding (assuming) you can ignore the error

Edit: Dont' mean to be rude, but, T.Core if you don't know what your talking about please don't try to help, your just confusing him
I'm sure it was an int for a reason, I bet functions called later on rely on it being an int..

Post the rest of the function if you want swev
 
I just want to be able to freely edit maxvalue, because it's inturn editing the criticalHit damage.

Right now 1=double I believe, so I would like to be able to do 0.6 or 0.8 or something
 
yes 1 should equal double.. I would use *= instead of <<= and not worry about rounding

it doesn't really make a difference if your off by .5 or whatever its going to retain most of the accuracy, and i'm pretty sure you can't hit for decimal values anyway and that's why maxValue is defined as an integer

just switch
maxValue <<= 1.2;
with
maxValue *= x; //where x equals whatever you want to multiply the number by 0.6, 0.8 ect
 
warnings don't prevent it from compiling only errors do

if you really want to get rid of the warning (which is unnecessary)..
just explicitly cast it to an int
maxValue = int(maxValue *x);
 
Back
Top