ID:205737
 
Keywords: mob, proc, undefined, var
(See the best response by Forum_account.)
Code:
world/mob = /mob/Player; // Fixed typo. Still gives error.

client/North() {
if(src.mob.IsInMainMenu) {
src.mob.MoveOption(1);
} else {
return ..();
}
}

client/South() {
if(src.mob.IsInMainMenu) {
src.mob.MoveOption(2);
} else {
return ..();
}
}

mob/Player/proc/MoveOption(var/Direction) {
src << "Ew, i'm not done yet... [Direction]";
}

mob/Player/var
IsInMainMenu;


Problem description: It says MoveOption() and IsInMainMenu undefined proc and undefined var, when they're both defined and world.mob is set to mob/Player...
Instead of SRC.MOB try client.mob or possible even just mob.

But client.mob is the one you are looking for.
Nothing...
As in nothing you mean what?, another question you have ; almost everywhere.. BYOND doesn't need these at the end of each block unlike PHP...
I mean i still keep getting the errors. Ah about the ; it's since i used them a lot in C++ and now i can't stop using them ,_,
Make sure you're not overwriting your movements elsewhere.
Also, are you sure IsInMainMenu is set? Try removing that ; from the end of the variable name.
I'm sure that i'm not overwriting the movements. :/ Also yeah, it is set.

Seems like client.mob "doesn't" know that mob is mob/Player/ and not mob/
Try
client/North() {
world << "Look! I'm a [src.mob.type]!"
world << src.mob.IsInMainMenu
if(src.mob.IsInMainMenu) {
src.mob.MoveOption(1);
} else {
return ..();
}
}


What does that return?
Procedures.dm:3:error: src.mob.IsInMainMenu: undefined var
Procedures.dm:4:error: src.mob.MoveOption: undefined proc

Errors. :P I'll say this is a bug.

EDIT: If i take out the code that gives error it returns this:

Look! I'm a /mob/Player!
Correct me if I'm wrong, but isn't it...
world/mob = /mob/Player;
^ Lol yeah, i wrote it wrong on the Main Post. Still it gives the error.
Try the following:

/mob/Player/
Login()
..()
world << "PLAYER LOGGED IN."


Also in some of your code you know works output the current mob's type.

Also use Find to make sure you're not overwriting yourself somewhere.
I'm really sure i'm not overwriting myself, code isn't too long since i've just started. And yes, mob/Player/Login() works fine since i call a proc out of that proc.
In response to Ocean King
Ocean King wrote:
Procedures.dm:3:error: src.mob.IsInMainMenu: undefined var
Procedures.dm:4:error: src.mob.MoveOption: undefined proc

Errors. :P I'll say this is a bug.

EDIT: If i take out the code that gives error it returns this:

Look! I'm a /mob/Player!

I see why you're getting those errors.
It's because you're using client/North()

The compiler doesn't understand nor care what type the src.mob is, by default it's just /mob/

What you'll want to do in this case is...
client/North() {
var/mob/Player/P = src.mob
world << "Look! I'm a [src.mob.type]!"
world << P.IsInMainMenu
if(P.IsInMainMenu) {
P.MoveOption(1);
} else {
return ..();
}
}


It's called Typecasting.
Procedures.dm:5:error: P.mob.IsInMainMenu: undefined var
Procedures.dm:6:error: P.mob.IsInMainMenu: undefined var
Procedures.dm:7:error: P.mob.MoveOption: undefined var
Procedures.dm:3:warning: P: variable defined but not used
Procedures.dm:16:error: P.mob.IsInMainMenu: undefined var
Procedures.dm:17:error: P.mob.IsInMainMenu: undefined var
Procedures.dm:18:error: P.mob.MoveOption: undefined var
Procedures.dm:14:warning: P: variable defined but not used

,_,
Sorry, modified my code above.
That should be fixed now?

Does it run okay?
Seems to be working, thanks. However i'll do a bug report/feature request so we can do it in that way.
I think the issue is client.mob is typecast as /mob, therefore /mob/Player values aren't going to be there. So just re-typecast:

client/proc/test()
var/mob/Player/m = mob
// Do everything with m instead of mob


Or use the : operator instead and istype() to be safe.
Oops, seems like I was beat to the punch!
It's not a bug.
Basically, when you refer to src.mob, because the mob's type could be potentially anything, it's just a /mob/.
That's the way the language works, it's how most languages work, many languages have typecasting.

http://en.wikipedia.org/wiki/Type_conversion
In computer science, type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies or type representations. One example would be small integers, which can be stored in a compact format and converted to a larger representation when used in arithmetic computations. In object-oriented programming, type conversion allows programs to treat objects of one type as one of their ancestor types to simplify interacting with them.
Each programming language has its own rules on how types can be converted. In general, both objects and fundamental data types can be converted. In most languages, the word coercion is used to denote an implicit conversion, either during compilation or during run time. A typical example would be an expression mixing integer and floating point numbers (like 5 + 0.1), where the integers are normally converted into the latter. Explicit type conversions can either be performed via built-in routines (or a special syntax) or via separately defined conversion routines such as an overloaded object constructor.
Page: 1 2 3