Stuck on a piece of code
I need help with a problem from someone with more C++ exp.
I have some code that I just can't put the final cap on. Here it is: This code is in Bot::FillSpawnStruct Code:
//CRIIMSON: Get BotID And this gets called Code:
uint32 Bot::GetEquipmentColor(int8 material_slot, uint32 botid) const If I remove the const on Bot::GetEquipmentColor (as it is above) the color value is transfered but it doesnt show in game If I leave it a const I cant put a pointer in the function to check botid (because the ID can change) so I tried to add the second variable sent to it. This sends and retieves the correct info from db but again it doesnt show in game. Which is weird because the slotid changes fine even when defined as a const I know the function called like: uint32 Bot::GetEquipmentColor(int8 material_slot) const will change all of the colors of armor (and shows in game) if I set the return as a number like 1644825 (which is black). However, this wont allow a botid variable which is neccessary to get the correct bots color scheme. The only way I get it to work is not sending botid or having a pointer in the const to botid. going friggin crazy over this. So close I can taste it. Criimson |
Removing the const from the function just makes it not match the existing virtual function so it isn't called from base class pointers.
That means Mob::SendWearChange can't call your new function which is where it seems the actual work of changing the colors happens. You said the ID you have at the time FillSpawnStruct is called isn't the same ID that the bot has once it is spawned? Have you considered using GetBotIDByBotName to look it up inside your new Bot::GetEquipmentColor function? I'm also a little confused why the part where you are setting the slotid is inside a while loop. In the best case where a valid material slot is passed the while loop has no effect. If for whatever reason an invalid material slot is passed it's an endless loop. You should probably replace all of that with Inventory::CalcSlotFromMaterial() anyway. |
No the ID passed is always correct
I just can't call it from the const using a pointer such as botid = this->GetBotID(); //this causes an error at compile I can send botid like the code above but it doesn't show in game on the bots. Meaning the Say("Checks") all show that every variable has exactly what it is supposed to have but it isnt showing. To test if my code worked in some degree what I did was: Code:
uint32 Bot::GetEquipmentColor(int8 material_slot) const Criimson EDIT: and I renamed the function GetBotEquipmentColor to keep people from getting it confused with the ones in MoB:: or Client:: EDIT EDIT: The while statement was for convenience. It will always show == 0 on call and it is only called by the items that show on bots so there is no chance of a loop happening as my code stands now. |
Make GetBotID const.
Code:
uint32 GetBotID() const { return _botID; } Actually, looking at the code all of these should be const. If you fix them in the header you'll have to fix the two non-inline functions in the cpp file as well. Code:
// "GET" Class Methods |
Quote:
I still don't get the convenience part of the while loop. It doesn't do anything useful except introduce the possibility for an infinite loop. Even though the existing code may not cause a problem for you today you should always be pragmatic and check your inputs to protect against error. Anyway, if you replace it with the existing function Inventory::CalcSlotFromMaterial() that does the same thing then your code is cleaner, doesn't rely on magic numbers, and doesn't violate the DRY principle. |
Quote:
Edit: This is all a learning experience for me. My C++ is still at a novice level. I am learning by reading the code and in this project there is a lot of it :) Quote:
Quote:
What magic numbers? Criimson EDIT: Nice function - will totally use that, thanks |
Yes, if you name the function differently or change its signature then it isn't connected to the functions in base classes, but then you also aren't going to have it called from Mob::FillSpawnStruct or Mob::SendWearChange which might be important.
The call from Mob::FillSpawnStruct looks like it probably isn't important because the data is overwritten right after that by the Bot function, but Mob::SendWearChange looks more important. If it can't call the bot function the colors may not show up, or they may disappear when the bot changes equipment. Magic numbers are whenever you use a hard coded number instead of a name for something in an enum or #define. Code:
//Magic numbers |
Well I took your advice.
Had to change the name back to GetEquipmentColor But redid the material to the function you suggested and then created a const GetBotIDForTint variable. Called it from the function and now the bots have dyed armor. Perfect. Kind of tired and I haven't ran an LDoN or fought much today so will complete the #bot armorcolor function tomorrow. Have it at a basic working right now. Thank you for the help. It was requested for bots and I learned a ton working on it. Criimson |
Quote:
|
All times are GMT -4. The time now is 08:28 PM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.