ID:143894
 
Code:
turf
Battle_Grass
icon = 'Landscapes.dmi'
icon_state="Invis"
Enter()
usr.pkmnbattle()
mob/proc
pkmnbattle(M/mob in oview(2))
usr.random=rand(1,2)
if(usr.random==1)
return
if(usr.random==2)
usr << "<b><font color=purple>Encounter!"
usr.Frozen = 1
if(usr.pokemon=="Chikorita")
usr.random=rand(1,2)
usr.dir = WEST
if(usr.random==1)
usr.loc=locate(7,98,2)
switch(input("Select an Option.")in list("Attack","Run"))
if("Attack")
switch(input("Select an Attack.")in list("Tackle","Leer"))
if("Tackle")
usr << "<font color=white>[pokemon]<font color=purple> used Tackle on the Enemy!"
M.Health -= usr.Strength*3/5


Problem description:

My error is:

155:error:M.Health:undefined var


However; at the top of the complete code I have:

mob/var
tmp/Frozen = 0
tmp/Motion = 0
tmp/Delay = 1
inbattle = 0
tmp/Bnum = 0
Health = 20
Strength = 7
exp = 0
maxexp = 25
Defense = 3
MaxHealth = 20
Level = 5
random = 0
pokemon = ""

As you can see; I clearly made a variable of 'Health' and 'MaxHealth'...
Help? Please? So I could get on with my life!? [ I SERIOUSLY have been working on this for 3 freaking hours finding a combonation that worked within the code... it has something to do with: M/mob in oview(2), right? ]
First, please don't be discouraged. We all start somewhere.

With that said, if that is really the result of 3 hours of work, I think you should go back to the drawing board and read through the DM Guide and some tutorials.

The most obvious mistake in the proc is your usage of usr. This is a common mistake that many new developers encounter. Understanding and avoiding it is one of the first major hurdles in becoming a decent BYOND developer. Read LummoxJR's BYONDscape article "usr Unfriendly" for more info. To sum it up, don't use usr in procs unless they are a direct result of client interaction (Click, directional stuff, etc).

Next, there are three problems with your proc's argument definition.

1: it's mob/M, not M/mob. The type goes first (mob) followed by the variable name (M)
2: in oview(2) is something you'd add to a verb's argument definition, procs work differently.
3: You're not actually passing arguments to the proc.

It'd take quite a bit of writing to explain these all in detail, and it's kind of late for me. I'd suggest reading Chapter 5 of the DM guide and going through some basic tutorials to get a better understanding of procs.
Simply replace M.Health with the search operater to make it M:Health
In response to Tails5
The search operator is inefficient. Code properly and you won't need to use it.
Mintee wrote:
Code:
> turf
> Battle_Grass
> icon = 'Landscapes.dmi'
> icon_state="Invis"
> Enter()
> usr.pkmnbattle()
> mob/proc
> pkmnbattle(M/mob in oview(2))
> usr.random=rand(1,2)
> if(usr.random==1)
> return
> if(usr.random==2)
> usr << "<b><font color=purple>Encounter!"
> usr.Frozen = 1
> if(usr.pokemon=="Chikorita")
> usr.random=rand(1,2)
> usr.dir = WEST
> if(usr.random==1)
> usr.loc=locate(7,98,2)
> switch(input("Select an Option.")in list("Attack","Run"))
> if("Attack")
> switch(input("Select an Attack.")in list("Tackle","Leer"))
> if("Tackle")
> usr << "<font color=white>[pokemon]<font color=purple> used Tackle on the Enemy!"
> M.Health -= usr.Strength*3/5
>

Problem description:

My error is:

155:error:M.Health:undefined var

However; at the top of the complete code I have:

mob/var
> tmp/Frozen = 0
> tmp/Motion = 0
> tmp/Delay = 1
> inbattle = 0
> tmp/Bnum = 0
> Health = 20
> Strength = 7
> exp = 0
> maxexp = 25
> Defense = 3
> MaxHealth = 20
> Level = 5
> random = 0
> pokemon = ""

As you can see; I clearly made a variable of 'Health' and 'MaxHealth'...
Help? Please? So I could get on with my life!? [ I SERIOUSLY have been working on this for 3 freaking hours finding a combonation that worked within the code... it has something to do with: M/mob in oview(2), right? ]
It would be best if you made your code smaller, and never i mean never use usr in a proc.
Try somthing like this..
mob/var
tmp/Frozen = 0
tmp/Motion = 0
tmp/Delay = 1
inbattle = 0
BattleOpponent = null
tmp/Bnum = 0
Health = 20
Strength = 7
exp = 0
maxexp = 25
Defense = 3
MaxHealth = 20
Level = 5
random = 0
pokemon = ""
turf
Battle_Grass
icon = 'Landscapes.dmi'
icon_state="Invis"
Enter()
usr.pkmnbattle()
mob/proc
pkmnbattle(mob/M in oview(2))
M = src.BattleOpponent
src.random=rand(1,2)
if(src.random)return
if(src.random==2)
src << "<b><font color=purple>Encounter!"
src.Frozen = 1
if(src.pokemon=="Chikorita")
src.random=rand(1,2)
src.dir = WEST
if(src.random==1)src.loc=locate(7,98,2)
switch(input(src,"Select an Option.")in list("Attack","Run"))
if("Attack")
switch(input(src,"Select an Attack.")in list("Tackle","Leer"))
if("Tackle")
src<< "<font color=white>[pokemon]<font color=purple> used Tackle on the Enemy!"
M.Health -= src.Strength*3/5

That should work alot better im guessing. You have to specify what M is because in your code its registering M as null.
Grand
In response to KillerGrand
You still didn't fix the core usr abuse issue. Without addressing important stuff like that it's hard to say if your changes would be any good or not.

Lummox JR
In response to Tails5
Tails5 wrote:
Simply replace M.Health with the search operater to make it M:Health

See, that's the sort of advice that's always wrong. It's not even a little bit right. Let's explore why.

  • Advising the use of the : operator in place of . is always wrong automatically. There is always a way to fix the problem without resorting to : except in some very advanced cases where there would be no way whatsoever to know what the var's type was.
  • The . operator can almost always be used successfully as long as you either define the var with the correct type, or type-cast it into another var with the correct type.
  • The actual problem here is that M itself does not exist.

    There are two major problems with this code. The first is that it's stuffed to the gills with usr abuse. usr has no place in procs. The second problem is that M is improperly defined; he's using M/mob instead of mob/M.

    Lummox JR
In response to KillerGrand
Eh; now we got M.Health; undefined...
M undefined. Now what do I do? I looked at Chapter 5 for a bit, still didn't find it for any use to me. (Sorry, Zag.) >_<;
In response to Mintee
now look at my code and try that it should work now..
In response to Mintee
Or perhaps you 2 should stop ignoring Lummox, he entitled all of the code problems AND the one big problem you asked about.
In response to Mintee
Whoops, I meant Chapter 6 (Procs), not Chapter 5 (Variables). Sorry. Good reading anyways though.

Anyway, the thing is when you have a proc definition with stuff between parentheses like that, that is called an argument. In order to use it you have to pass an argument to the proc. It's not like a verb where the client chooses the arguments when it is executed.

Example of passing arguments to a proc:
mob/verb/callproc()
DoThisProc("Hello", "World", src)


Example of using arguments in a proc:
proc/DoThisProc(T, T2, mob/M) //T and T2 are text strings
M << "[T] [T2]"


Will display "Hello World" to M, which is the mob who the verb belongs to.
Your code looks to be ineffective in the long run (Why do you need to be Chikorita just to battle properly? And if you fixed it using the way you are doing now, you got a lot of code to edit when the game gets bigger)

... Lets see anyway.

pkmnbattle(M/mob in oview(2))

M/mob is the wrong way around from my experiences. Its should mob/M.

Also, you can define variables in procs, and when you want to call them, you set the variables you want the proc to use in the order you want to use them in, such as...

proc/pkmnbattle(var/mob/attacker,var/mob/defender)

You don't even need the var/ part for procs

And to call it...

pkmnbattle(me,noob)


That's just a example, and your probably wondering why I have an attacker and defender variable.

The reason I have it is simple: The attacker is taking their turn, the defender is waiting. When the turn is over, make the defender the attacker and the attacker the defender. The simple way to coding fights.
In response to KillerGrand
It took it down by one error. =/ [That was using Redlines, and yours, Killer.]

Error:
Main Code.dm:41:error:M.Health:undefined var
In response to Mintee
mob/var
tmp/Frozen = 0
tmp/Motion = 0
tmp/Delay = 1
inbattle = 0
BattleOpponent = null
tmp/Bnum = 0
Health = 20
Strength = 7
exp = 0
maxexp = 25
Defense = 3
MaxHealth = 20
Level = 5
random = 0
pokemon = ""
turf
Battle_Grass
icon = 'Landscapes.dmi'
icon_state="Invis"
Enter()
usr.pkmnbattle()
mob/proc
pkmnbattle(mob/M in oview(2))
M = src.BattleOpponent
src.random=rand(1,2)
if(src.random)return
if(src.random==2)
src << "<b><font color=purple>Encounter!"
src.Frozen = 1
if(src.pokemon=="Chikorita")
src.random=rand(1,2)
src.dir = WEST
if(src.random==1)src.loc=locate(7,98,2)
switch(input(src,"Select an Option.")in list("Attack","Run"))
if("Attack")
switch(input(src,"Select an Attack.")in list("Tackle","Leer"))
if("Tackle")
src<< "<font color=white>[pokemon]<font color=purple> used Tackle on the Enemy!"
M.Health -= src.Strength*3/5

You use this code u wont get any errors because i wont get any...
In response to KillerGrand
Ahhh... shizniz. Right when you post I just got rid of the battle arenas. >_<

-Remakes...-
In response to Mintee
Dude omg ..
In response to KillerGrand
Uh, why did you just repost with the same usr abuse again?

Lummox JR
In response to Lummox JR
Lummox JR wrote:
usr has no place in procs.
Lummox JR

Sorry Lummox....
Just to not get some rookie BYONDers confused... Usr is needed in some cases where the Usr is directly using the proc.. for example Click() Etc usr works like a charm in them cases.
In response to Granado Espada
Are you freaking kidding me? usr is Entered is like bring a knife to a gun fight.
In response to KillerGrand
turf
Battle_Grass
icon = 'Landscapes.dmi'
icon_state="Invis"
Enter(mob/M)
if(!ismob(M)||!M.client) return ..()
M.pkmnbattle()
return ..()


Just to fix that usr abuse Lummox was talking about.
Page: 1 2