RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Convert.ToInt32()

Convert.ToInt32()

Hiya, i'm trying to make a little script thingy here, and I can't seem to get Convert.ToInt32() to work. It simply gives me the error(s):

Code:
<filepath here>(49) : error C2065: 'Convert' : undeclared identifier
<filepath here>(49) : error C2228: left of '.ToInt32' must have class/struct/union type

Line 49 is:
Code:
        int hitsmax = Convert.ToInt32((1 / wep[sub].speed) * 3000);

So, at this point the best I can do is:
Code:
        int hitsmax = (int)((1 / wep[sub].speed) * 3000);
which doesn't convert it properly all the time.

What would I have to #include in order to declare Convert.ToInt32?

Thanks!
-Aiden
 

Malaperth

Wanderer
try

Code:
System.Convert.ToInt32((1 / wep[sub].speed) * 3000);

or if that still fails, do the calculation first, then convert the result (not sure why that would not work as you have it, though, unless you need another set of parentheses).
 
Malaperth said:
try

Code:
System.Convert.ToInt32((1 / wep[sub].speed) * 3000);
or if that still fails, do the calculation first, then convert the result (not sure why that would not work as you have it, though, unless you need another set of parentheses).

Nope :(

Code:
--------------------Configuration: WeaponArmor - Win32 Debug--------------------
Compiling...
WeaponArmor.cpp
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(50) : error C2065: 'System' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(50) : error C2228: left of '.Convert' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(50) : error C2228: left of '.ToInt32' must have class/struct/union type
Error executing cl.exe.
Creating browse info file...

WeaponArmor.exe - 3 error(s), 0 warning(s)

Another idea I had would be to Floor() them, but I wanted it so it rounds it. (int) doesn't seem to do it properly...


With the calculation done first, the result is the same (good idea though). Tried it as a double and a float. No difference.
 
Malaperth said:
Do you have using System; at the top of the class?

Uhh, no... It's using #include's. If I try to do using System; it buggers up still.

Like... so:

Code:
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(13) : error C2873: 'System' : symbol cannot be used in a using-declaration

Any suggestions on that? I tried to include system (shouldof said that before probably :\), but it gave me this and I was like "huh?"...
 

Malaperth

Wanderer
Ok, I'm confused as hell now... I thought 'include' was C++. I guess you'll have to wait for someone smarter than me. :) Sorry to waste your time. Hmmm... That IS C++, are you trying to write C# or C++?
 
Malaperth said:
ummm... check this:
Yea, that's the program i'm using. But I always thought my course was teaching C#... C++ was later on in the course... Though they were similar.

C++ Example
Code:
// Project 1 Cplusplus.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <conio.h>

int main(void)
{
    cout<<"HEY, you, i'm alive! Oh and Hello C++ World!" << endl;
    getch();
    return 0;
}


C# Example...
Code:
// Project 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>

int main(void)
{
    printf("Hello world!");
    getch();
    return 0;
}

Both of those are actually projects from a scripting course I had (both project 1 obviously... XD). But they're quite similar... The teacher said the first one was in C#, and the second in C++...

Unless he was wrong?
 

noobie

Wanderer
the first one is C++, the second is in C.

and what you are trying to do it use .net classes in your C++ code which you cant unless you do it in managed C++ that comes with .NET
 
Malaperth said:
Quit that class now. :) You know more than the teacher :eek:
It was a class that I already completed XD lol.

Well, now this is awkward... I'm searching around for a way to get this to work right now, but can't seem to find any sort of #include typeof thing.

Edit:
System::Convert::ToInt32 and System.Convert.ToInt32 give the exact same results... heh...
 

Nochte

Wanderer
IHaveRegistered said:
Yea, that's the program i'm using. But I always thought my course was teaching C#... C++ was later on in the course... Though they were similar.

C++ Example
Code:
// Project 1 Cplusplus.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <conio.h>

int main(void)
{
    cout<<"HEY, you, i'm alive! Oh and Hello C++ World!" << endl;
    getch();
    return 0;
}


C# Example...
Code:
// Project 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>

int main(void)
{
    printf("Hello world!");
    getch();
    return 0;
}

Both of those are actually projects from a scripting course I had (both project 1 obviously... XD). But they're quite similar... The teacher said the first one was in C#, and the second in C++...

Unless he was wrong?


...you're going to have to pm me the name of this "school" and "course" you took so i can go boof somebody. seriously. that shit's funny.
 

noobie

Wanderer
you might use atoi method. i think prototype was something like:
int atoi (char *)

char * c="5";
int myInt=atoi(c);

or

string c="5";
int myInt=atoi(c.c_str());


you cant use any .NET classes ..

edit:
Nochte: I dont think any teacher would tell something like that. I think Ihavereg. has misunderstood him..
Probably he was saying one of them C and the orher is C++. (although both have cpp extension)
 
atoi converts a string into an integer, i'm mainly trying to convert doubles to integers... I guess i'll give it a shot XD

If you wanna know what schoo, it's Ajax High School. ICS 4M1 is the course.
 
Top