Jump to content

Convert char to uint32_t


Go to solution Solved by VegaS™,

Recommended Posts

Hello, I am trying to do the following:

 

for (int i = 0; i < 30; ++i)
                {

                    if (dwEff== i)
                    {
                        char szEff[256];
                        sprintf(szEff, "EFFECT_REFINED+EFFECT_SWORD_EFF%d", i);
                        m_swordRefineEffectRight = szEff;
                    }
                }

 

But when I compile I get the error that it couldn't convert char to uint32_t.

How could I make this possible? Thank you

Edited by Dievs
Link to comment
Share on other sites

  • Forum Moderator

It's impossible what you're trying to do, this could be done in python very easily, like:

m_swordRefineEffectRight = eval("EFFECT_REFINED + EFFECT_SWORD_EFF_%d" % i);

But in C++ there's no built-in method, just a work-around, and shitty ways.

 

I don't know how it's working your system but in your case, you need something very simple, not to evaluate an expression when you can use effectSwordStartID + effectID:

m_swordRefineEffectRight = EFFECT_REFINED + EFFECT_SWORD_EFF_START + dwEff;

You just need to have the values ordered ascendingly.

  • Love 1
Link to comment
Share on other sites

  • Premium

We should probably see the rest of the code, but the compiler is telling you that with a reason. You cannot convert an array of chars to a numerical type. A solution would be setting m_swordRefineEffectRight = dwEff but then again, I am not really sure what you are trying to accomplish here. 

  • Love 1
Link to comment
Share on other sites

Thanks for answering.

What I am trying to do is replace this:

 

                 if (dwEff == 1)
                    m_swordRefineEffectRight = EFFECT_REFINED+EFFECT_SWORD_EFF1;
                else if (dwEff == 2)
                    m_swordRefineEffectRight = EFFECT_REFINED+EFFECT_SWORD_EFF2;
                else if (dwEff == 3)
                    m_swordRefineEffectRight = EFFECT_REFINED+EFFECT_SWORD_EFF3;
                else if (dwEff == 4)
                    m_swordRefineEffectRight = EFFECT_REFINED+EFFECT_SWORD_EFF4;
                else if (dwEff == 5)
                    m_swordRefineEffectRight = EFFECT_REFINED+EFFECT_SWORD_EFF5;
                else if (dwEff == 6)
                    m_swordRefineEffectRight = EFFECT_REFINED+EFFECT_SWORD_EFF6;

                **About 30 or 40 more**

 

for this:

 

for (int i = 0; i < 30; ++i)
                {

                    if (dwEff == i)
                    {
                        char szEff[256];
                        sprintf(szEff, "EFFECT_REFINED+EFFECT_SWORD_EFF%d", i);
                        m_swordRefineEffectRight = szEff;
                    }
                }

dwEff is an int value that identifies the value of the effect to give a weapon.

 

I guess I'll have to leave the long code as is, I thought it might be possible to reduce it to a for.

Thank you

 

Edited by Dievs
Link to comment
Share on other sites

  • Forum Moderator
10 minutes ago, VegaS™ said:

 

I don't know how it's working your system but in your case, you need something very simple, not to evaluate an expression when you can use effectSwordStartID + effectID:


m_swordRefineEffectRight = EFFECT_REFINED + EFFECT_SWORD_EFF_START + dwEff;

You just need to have the values ordered ascendingly.

Then you could do it as I said, it's the best method instead of using an array or something.

Can you show me the EFFECT_SWORD_EFF1....EFFECT_SWORD_EFF40 values from enum?

  • Love 1
Link to comment
Share on other sites

1 minute ago, VegaS™ said:

Entonces podrías hacerlo como dije, es el mejor método en lugar de usar una matriz o algo así.

¿Puede mostrarme los valores EFFECT_SWORD_EFF1 .... EFFECT_SWORD_EFF40 de la enumeración?

I currently have them like this:

 

        EFFECT_SMALLSWORD_EFF1, //dagger, fan, bell
        EFFECT_SMALLSWORD_EFF1_LEFT, //dagger, fan, bell
        EFFECT_BOW_EFF1, //bow
        EFFECT_SWORD_EFF1, // sword, two hand
        
        EFFECT_SMALLSWORD_EFF2, //dagger, fan, bell
        EFFECT_SMALLSWORD_EFF2_LEFT, //dagger, fan, bell
        EFFECT_BOW_EFF2, //bow
        EFFECT_SWORD_EFF2, // sword, two hand
        
        EFFECT_SMALLSWORD_EFF3, //dagger, fan, bell
        EFFECT_SMALLSWORD_EFF3_LEFT, //dagger, fan, bell
        EFFECT_BOW_EFF3, //bow
        EFFECT_SWORD_EFF3, // sword, two hand
        
        EFFECT_SMALLSWORD_EFF4, //dagger, fan, bell
        EFFECT_SMALLSWORD_EFF4_LEFT, //dagger, fan, bell
        EFFECT_BOW_EFF4, //bow
        EFFECT_SWORD_EFF4, // sword, two hand

Link to comment
Share on other sites

  • Forum Moderator
  • Solution

Then you'll need a small formula like this, for keeping the same values of enum:

This is the hidden content, please

So, in that way, you'll get the effect value multiplied by 4 depending on effectID.

Output:

dwEff = 1
m_swordRefineEffectRight = EFFECT_REFINED + 114

dwEff = 5
m_swordRefineEffectRight = EFFECT_REFINED + 130

dwEff = 12
m_swordRefineEffectRight = EFFECT_REFINED + 158

 

Edited by VegaS™
  • Love 3
Link to comment
Share on other sites

Solved, thanks to VegaS for their help.

 

If anyone ever wants to do something similar, they could use something like this:

 

for (int i = 0; i < 30; ++i) 
                {
                    if (dwEff == i) 
                        m_swordRefineEffectRight = EFFECT_REFINED + 110 + (dwEff * 4); 
                }

 

The code is adequate to what I have, so you should change the number 110 and * 4 depending on what you want to do
                

Many thanks to the two people who responded, special thanks to Vegas.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.