ID:151185
 
Ok, here's the code I need help with:
mob/var/obj/HP_bar = new
mob/Stat()
if(src.max_HP)
S = src.HP/src.max_HP
if(S < 0.25) HP_bar.icon = 'Bar4.dmi'
else if(S < 0.5) HP_bar.icon = 'Bar3.dmi'
else if(S < 0.75) HP_bar.icon = 'Bar2.dmi'
else HP_bar.icon = 'Bar1.dmi'
stat("HP: [src.max_HP] ",HP_bar)

if(src.max_shield)
S = src.shield/src.max_shield
if(S < 0.25) stat("shield","[src.max_shield] exhausted")
else if(S < 0.5) stat("shield","[src.max_shield] feeble")
else if(S < 0.75) stat("shield","[src.max_shield] fair")
else stat("shield","[src.max_shield] full")

if(src.max_iq)
S = src.iq/src.max_iq
if(S < 0.25) stat("dexterity","[src.max_iq] exhausted")
else if(S < 0.5) stat("mind","[src.max_iq] feeble")
else if(S < 0.75) stat("mind","[src.max_iq] fair")
else stat("mind","[src.max_iq] full")


if(src.max_dexterity)
S = src.dexterity/src.max_dexterity
if(S < 0.25) stat("armed","minimally")
else if(S < 0.5) stat("armed","lightly")
else if(S < 0.75) stat("armed","heavily")
else stat("armed","fully")


if(src.max_armor)
S = src.armor/src.max_armor
if(S < 0.25) stat("armored","minimally")
else if(S < 0.5) stat("armored","lightly")
else if(S < 0.75) stat("armored","heavily")
else stat("armored","fully")


if(!src.max_immunity) stat("immunity","none")
else
S = src.immunity/src.max_immunity
if(S < 0.25) stat("immunity","[src.max_immunity] very low")
else if(S < 0.5) stat("immunity","[src.max_immunity] low")
else if(S < 0.75) stat("immunity","[src.max_immunity] fair")
else stat("immunity","[src.max_immunity] strong")


stat("karma",round(src.karma))


if(src == usr && statpanel("inventory")) stat(src.contents)



Some of the indentation might be messed up, but anyway, when I compile, I get the following errors...:
Mob vars.dm:286:error:= :expected a constant expression
Mob vars.dm:289:error:S:bad var
Mob vars.dm:290:error:S:bad var
Mob vars.dm:291:error:S:bad var
Mob vars.dm:292:error:S:bad var
Mob vars.dm:297:error:S:bad var
Mob vars.dm:298:error:S:bad var
Mob vars.dm:299:error:S:bad var
Mob vars.dm:300:error:S:bad var
Mob vars.dm:304:error:S:bad var
Mob vars.dm:305:error:S:bad var
Mob vars.dm:306:error:S:bad var
Mob vars.dm:307:error:S:bad var
Mob vars.dm:312:error:S:bad var
Mob vars.dm:313:error:S:bad var
Mob vars.dm:314:error:S:bad var
Mob vars.dm:315:error:S:bad var
Mob vars.dm:320:error:S:bad var
Mob vars.dm:321:error:S:bad var
Mob vars.dm:322:error:S:bad var
Mob vars.dm:323:error:S:bad var
Mob vars.dm:329:error:S:bad var
Mob vars.dm:330:error:S:bad var
Mob vars.dm:331:error:S:bad var
Mob vars.dm:332:error:S:bad var


What's wrong with S? Help please!
Thanks,
Gilser
Ok, here's the code I need help with:
mob/var/obj/HP_bar = new
mob/Stat()
if(src.max_HP)
S = src.HP/src.max_HP

1) You can't initialize a mob's var with anything but a constant value, so "new" won't work for HP_bar there. Instead, override the mob's New() proc to create HP_bar when the mob is created. Someone had the same problem this morning; there's more information in that post.

2) At the beginning of your proc, add the line:

var/S
In response to Guy T.
2) At the beginning of your proc, add the line:

var/S

When I do this, the errors turn into warning! That can't possibly be good eh?
And some of them just make it say "var/S: Bad var"

Thanks,
Gilser

Oh yeah, can you make a link to that earlier post? If not i'll get off my lazy butt and do it myself, Thanks!
In response to Gilser
When I do this, the errors turn into warning! That can't possibly be good eh?
And some of them just make it say "var/S: Bad var"

Hmm... not sure. Try posting about 10 or 12 lines of the new code, with that line in the middle.


Oh yeah, can you make a link to that earlier post? If not i'll get off my lazy butt and do it myself, Thanks!

Oops... it was actually last night, not this morning. See "Re: list problem" in Code Problems.
In response to Guy T.

Hmm... not sure. Try posting about 10 or 12 lines of the new code, with that line in the middle.


mob/var/obj/HP_bar = new
mob/Stat()
if(src.max_HP)
var/S = src.HP/src.max_HP
if(var/S < 0.25) HP_bar.icon = 'Bar4.dmi'
else if(var/S < 0.5) HP_bar.icon = 'Bar3.dmi'
else if(var/S < 0.75) HP_bar.icon = 'Bar2.dmi'
else HP_bar.icon = 'Bar1.dmi'
stat("HP: [src.max_HP] ",HP_bar)

if(src.max_shield)
var/S = src.shield/src.max_shield
if(var/S < 0.25) stat("shield","[src.max_shield] exhausted")
else if(var/S < 0.5) stat("shield","[src.max_shield] feeble")
else if(var/S < 0.75) stat("shield","[src.max_shield] fair")
else stat("shield","[src.max_shield] full")

if(src.max_iq)
var/S = src.iq/src.max_iq
if(var/S < 0.25) stat("dexterity","[src.max_iq] exhausted")
else if(var/S < 0.5) stat("mind","[src.max_iq] feeble")
else if(var/S < 0.75) stat("mind","[src.max_iq] fair")
else stat("mind","[src.max_iq] full")


if(src.max_dexterity)
var/S = src.dexterity/src.max_dexterity
if(var/S < 0.25) stat("armed","minimally")
else if(var/S < 0.5) stat("armed","lightly")
else if(var/S < 0.75) stat("armed","heavily")
else stat("armed","fully")


if(src.max_armor)
var/S = src.armor/src.max_armor
if(var/S < 0.25) stat("armored","minimally")
else if(var/S < 0.5) stat("armored","lightly")
else if(var/S < 0.75) stat("armored","heavily")
else stat("armored","fully")


if(!src.max_immunity) stat("immunity","none")
else
var/S = src.immunity/src.max_immunity
if(var/S < 0.25) stat("immunity","[src.max_immunity] very low")
else if(var/S < 0.5) stat("immunity","[src.max_immunity] low")
else if(var/S < 0.75) stat("immunity","[src.max_immunity] fair")
else stat("immunity","[src.max_immunity] strong")


stat("karma",round(src.karma))


if(src == usr && statpanel("inventory")) stat(src.contents)



Thanks,
Gilser
In response to Gilser
Wow! That's the longest 10 or 12 lines I ever saw. :)

Anyway, I think I know what the problem is. Instead of adding var/S at the top of the procedure, you added it everywhere that you were formerly using S. But you only have to use "var" once, when you originally declare it as a variable. After that, you just refer to it as S.

Here's a small example:

//current code:
proc/bla()
var/S = bla
if(bla)
var/S = bla
else
var/S = bla

//what you need to do:
proc/bla()
var/S = bla
if(bla)
S = bla
else
S = bla

Hope this helps!
In response to Guy T.
I have the cursed code! When I did that it ADDED errors, not all the errors look like this:
Mob vars.dm:290:error: if: missing comma ',' or right-paren ')'
Mob vars.dm:290:error: if: expected end of statement
Mob vars.dm:290:error: missing condition
Mob vars.dm:291:error: HP_bar: expected end of statement
Mob vars.dm:292:error: missing condition
Mob vars.dm:293:error: HP_bar: expected end of statement
Mob vars.dm:294:error: missing condition
Mob vars.dm:295:error: HP_bar: expected end of statement
Mob vars.dm:300:error: missing condition
Mob vars.dm:301:error: stat: expected end of statement
Mob vars.dm:302:error: missing condition
Mob vars.dm:303:error: stat: expected end of statement
Mob vars.dm:304:error: missing condition
Mob vars.dm:305:error: stat: expected end of statement
Mob vars.dm:310:error: missing condition
Mob vars.dm:311:error: stat: expected end of statement
Mob vars.dm:312:error: missing condition
Mob vars.dm:313:error: stat: expected end of statement
Mob vars.dm:314:error: missing condition
Mob vars.dm:315:error: stat: expected end of statement
Mob vars.dm:322:error: missing condition
Mob vars.dm:323:error: stat: expected end of statement
Mob vars.dm:324:error: missing condition
Mob vars.dm:325:error: stat: expected end of statement
Mob vars.dm:331:error: missing condition
Mob vars.dm:332:error: stat: expected end of statement
Mob vars.dm:333:error: missing condition
Mob vars.dm:334:error: stat: expected end of statement
Mob vars.dm:335:error: missing condition
Mob vars.dm:336:error: stat: expected end of statement
Mob vars.dm:343:error: missing condition
Mob vars.dm:344:error: stat: expected end of statement
Mob vars.dm:345:error: missing condition
Mob vars.dm:346:error: stat: expected end of statement
Mob vars.dm:347:error: missing condition
Mob vars.dm:348:error: stat: expected end of statement
Mob vars.dm:914:error: missing while statement
Here's the new code:
mob/var/obj/HP_bar = new
mob/Stat()
if(src.max_HP)
(var/S = src.HP/src.max_HP
if
(var/S < 0.25) HP_bar.icon = 'Bar4.dmi'
else if
(var/S < 0.5) HP_bar.icon = 'Bar3.dmi'
else if
(var/S < 0.75) HP_bar.icon = 'Bar2.dmi'
else HP_bar.icon = 'Bar1.dmi'
stat("HP: [src.max_HP] ",HP_bar)

if(src.max_shield)var/S = src.shield/src.max_shield
if
(var/S < 0.25) stat("shield","[src.max_shield] exhausted")
else if
(var/S < 0.5) stat("shield","[src.max_shield] feeble")
else if
(var/S < 0.75) stat("shield","[src.max_shield] fair")
else stat("shield","[src.max_shield] full")

if(src.max_iq)
var/S = src.iq/src.max_iq
if
(var/S < 0.25) stat("dexterity","[src.max_iq] exhausted")
else if
(var/S < 0.5) stat("mind","[src.max_iq] feeble")
else if
(var/S < 0.75) stat("mind","[src.max_iq] fair")
else stat("mind","[src.max_iq] full")


if(src.max_dexterity)
var/S = src.dexterity/src.max_dexterity
if(var/S < 0.25) stat("armed","minimally")
else if
(var/S < 0.5) stat("armed","lightly")
else if
(var/S < 0.75) stat("armed","heavily")
else stat("armed","fully")


if(src.max_armor)
var/S = src.armor/src.max_armor
if
(var/S < 0.25) stat("armored","minimally")
else if
(var/S < 0.5) stat("armored","lightly")
else if
(var/S < 0.75) stat("armored","heavily")
else stat("armored","fully")


if(!src.max_immunity) stat("immunity","none")
else
var/S = src.immunity/src.max_immunity
if
(var/S < 0.25) stat("immunity","[src.max_immunity] very low")
else if
(var/S < 0.5) stat("immunity","[src.max_immunity] low")
else if
(var/S < 0.75) stat("immunity","[src.max_immunity] fair")
else stat("immunity","[src.max_immunity] strong")


stat("karma",round(src.karma))


if(src == usr && statpanel("inventory")) stat(src.contents)

Thanks,
Gilser
In response to Gilser
if(src.max_HP)
(var/S = src.HP/src.max_HP
if
(var/S < 0.25) HP_bar.icon = 'Bar4.dmi'

Look at that second 'if' in the example above... looks awfully lonely, doesn't it? It has no condition to check!

Actually, it does, but the condition is on the wrong line. It should read like this:

if(S < 0.25)
HP_bar.icon = 'bla'

And I notice you're still using var/S! Remember, you only use var with S once, to let the compiler know you've approved S as a variable. After that, you just use S.
In response to Guy T.

Actually, it does, but the condition is on the wrong line. It should read like this:

if(S < 0.25)
HP_bar.icon = 'bla'

Ok, I did that, and it worked, at first. But then when I was to 3 errors (not even this topic-related) I compile 1 extra time and suddenly I got 27 errors and 2 warnings! I know that 3 of them are from something different, but here's the code:
mob/var/obj/HP_bar = new
mob/Stat()
if(src.max_HP)
var/S = src.HP/src.max_HP
if(S < 0.25)
HP_bar.icon = 'Bar4.dmi'
else if(S < 0.5)
HP_bar.icon = 'Bar3.dmi'
else if(S < 0.75)
HP_bar.icon = 'Bar2.dmi'
else
HP_bar.icon = 'Bar1.dmi'
stat("HP: [src.max_HP] ",HP_bar)

if(src.max_shield)
S = src.shield/src.max_shield
if(S < 0.25)
stat("shield","[src.max_shield] exhausted")
else if(S < 0.5)
stat("shield","[src.max_shield] feeble")
else if(S < 0.75)
stat("shield","[src.max_shield] fair")
else
stat("shield","[src.max_shield] full")

if(src.max_iq)
S = src.iq/src.max_iq
if(S < 0.25)
stat("dexterity","[src.max_iq] exhausted")
else if(S < 0.5)
stat("mind","[src.max_iq] feeble")
else if(S < 0.75)
stat("mind","[src.max_iq] fair")
else
stat("mind","[src.max_iq] full")


if(src.max_dexterity)
S = src.dexterity/src.max_dexterity
if(S < 0.25)
stat("armed","minimally")
else if(S < 0.5)
stat("armed","lightly")
else if(S < 0.75)
stat("armed","heavily")
else
stat("armed","fully")


if(src.max_armor)
S = src.armor/src.max_armor
if(S < 0.25)
stat("armored","minimally")
else if(S < 0.5)
stat("armored","lightly")
else if(S < 0.75)
stat("armored","heavily")
else
stat("armored","fully")


if(!src.max_immunity) stat("immunity","none")
else
S = src.immunity/src.max_immunity
if(S < 0.25)
stat("immunity","[src.max_immunity] very low")
else if(S < 0.5)
stat("immunity","[src.max_immunity] low")
else if(S < 0.75)
stat("immunity","[src.max_immunity] fair")
else
stat("immunity","[src.max_immunity] strong")


stat("karma",round(src.karma))


if(src == usr && statpanel("inventory")) stat(src.contents)



And the errors:

Mob vars.dm:286:error:= :expected a constant expression
Mob vars.dm:290:error:S:bad var
Mob vars.dm:292:error:S:bad var
Mob vars.dm:294:error:S:bad var
Mob vars.dm:301:error:S:bad var
Mob vars.dm:302:error:S:bad var
Mob vars.dm:304:error:S:bad var
Mob vars.dm:306:error:S:bad var
Mob vars.dm:312:error:S:bad var
Mob vars.dm:313:error:S:bad var
Mob vars.dm:315:error:S:bad var
Mob vars.dm:317:error:S:bad var
Mob vars.dm:324:error:S:bad var
Mob vars.dm:325:error:S:bad var
Mob vars.dm:327:error:S:bad var
Mob vars.dm:329:error:S:bad var
Mob vars.dm:336:error:S:bad var
Mob vars.dm:337:error:S:bad var
Mob vars.dm:339:error:S:bad var
Mob vars.dm:341:error:S:bad var
Mob vars.dm:349:error:S:bad var
Mob vars.dm:350:error:S:bad var
Mob vars.dm:352:error:S:bad var
Mob vars.dm:354:error:S:bad var
Mob vars.dm:289:S :warning: variable defined but not used

Thanks,
Gilser
In response to Gilser
mob/var/obj/HP_bar = new

You can't do that, remember?

mob/Stat()
if(src.max_HP)
var/S = src.HP/src.max_HP
if(S < 0.25)
HP_bar.icon = 'Bar4.dmi'

You have to do it like this; if you declare a variable in an indented part of the code, the compiler will only expect that variable to apply to the indented part. Here's what it should look like:

mob/var/obj/HP_bar
mob/New()
..()
src.HP_bar = new
mob/Stat()
var/S
if(src.max_HP)
S = src.HP/src.max_HP
if(S < 0.25)
HP_bar.icon = 'Bar4.dmi'

//and so on, with S, not var/S
In response to Spuzzum
It works now! But can you help me with the rest of the errors? There's just 1, here's the code:
mob/Stat()
stat("description",src.desc)
if(src == usr) stat(src.contents)

var/list/fighterLevels = list(1000, 2000, 4000, 8000, 16000)

mob
var/list/expLevelList
var/exp
var/level

player
expLevelList = fighterLevels
level = 1

proc/AddExperience(myAmount)
exp += myAmount
if(exp >= expLevelList[level])
src << "You are now level [++level]!"

The error is:

players.dm:13:error:fighterLevels:expected a constant expression

Thanks,
Gilser

I've edited this message 4 times now!
In response to Gilser
mob/Stat()
stat("description",src.desc)
if(src == usr) stat(src.contents)

var/list/fighterLevels = list(1000, 2000, 4000, 8000, 16000)

mob
var/list/expLevelList
var/exp
var/level

player
expLevelList
level = 1
New()
..()
src.expLevelList = fighterLevels

proc/AddExperience(myAmount)
exp += myAmount
if(exp >= expLevelList[level])
src << "You are now level [++level]!"

In response to Spuzzum
Here's the code I'm having problems with...:
mob/choosing_character/proc/CreateNewCharacter()
// In this case, the code creates a /mob/human or /mob/ogre with the specified attributes.

// Get the character information from them. (You would probably want to do with this a browser page.)
var/prompt_title = "New Character"
var/help_text = "Type a name"
var/default_value = key
var/char_name = input(src, prompt_title, default_value, help_text) as null|text

if (!char_name)
// Guess they don't want to create a new character after all, so return them to the character list.
src.ChooseCharacter()
return

// Make sure there isn't already a character named that.
// Character names are stored as ckey, so get the ckey version of the name.
var/ckey_name = ckey(char_name)
var/list/characters = CharacterList()
if (characters.Find(ckey_name))
alert("You already have a character named that! Please choose another name.")
src.CreateNewCharacter()
return

var/list/races = list("Kid", "Gramps", "Dragon", "Ninja", "Fairy")
help_text = "Which race would you like to be?"
default_value = "Kid"
var/char_race = input(src, prompt_title, default_value, help_text) in races


// Okay we have enough information, so it's time to create the character and switch the player to it.
var/mob/new_mob
switch(char_race)
if ("Gramps") new_mob = new /mob/Gramps()
if ("Kid") new_mob = new /mob/Kid()
if ("Dragon") new_mob = new /mob/Dragon()
if ("Ninja") new_mob = new /mob/Ninja()
if ("Fairy") new_mob = new /mob/Fairy()

// Set the attributes.
new_mob.name = char_name
new_mob.eye_color = eye_color

// Now switch the player client over to the new mob and delete myself since I'm no longer needed.
src.client.mob = new_mob
del(src)

mob
var
eye_color

Login()
..()
// This is just here for this sample, to make it clear which mob you've logged into.
if (!istype(src, /mob/choosing_character))
sample_report()

proc
sample_report()
src << "

"
src << "\blue You are [name]."
src << "\blue Your class is [type]."

mob/Kid
icon='player.dmi'
Login()
loc = locate(10,10,1)

mob/Gramps
icon='Gramps.dmi'
Login()
loc = locate(10,10,1)
mob/Dragon
icon='mage.dmi'
Login()
loc = locate(10,10,1)
mob/Ninja
icon='ninja.dmi'
Login()
loc = locate(10,10,1)
mob/Fairy
icon='fairy.dmi'
Login()
loc = locate(10,10,1)

When I try to run, it keeps saying "Sorry, unable to load that character!" I tried making a new key and it still said the same thing.
Thanks,
Gilser
In response to Gilser
When I try to run, it keeps saying "Sorry, unable to load that character!"

I didn't spot that error message in the code you posted, so it is impossible to tell why it is saying that. Search through the code you are using and find where it is generating that exact message. Maybe you will be able to figure out why it is failing.

In general, I find the following practice essential to programming: make changes in small increments. It is not always easy, but it saves you a lot of time in the long run if you can make a small change, test it, then make the next change, test that, and so on. Otherwise, it's pretty hard to figure out where (in the thousands of possible lines of code) the danged problem is!

Best of luck.

--Dan
In response to Dan
Here it is!:

if (result == newCharacterChoice)
src.CreateNewCharacter() // This is for you to handle in whatever way you wish.
else
// Load the specified character.
var/success = src.client.LoadMob(result)

if (success)
// Delete myself, since I'm not longer needed.
del(src)
else
// The load failed, so give them an alert, then show them the character list again.
alert("Sorry, unable to load that character!")
src.ChooseCharacter()

CharacterList()
// Returns a list of the player's existing characters.
var/savefile/F = new("players.sav")
F.cd = "/[ckey]"
var/list/characters = F.dir
return characters



Thanks,
Gilser
In response to Gilser
success = src.client.LoadMob(result)

LoadMob() must be returning a false value. Check what is getting passed in and what it is returning like this:

success = src.client.LoadMob(result)
world.log << "LoadMob([result]) = [success]"


If you don't see the problem, then try posting the LoadMob() proc so we can take a look at that. This looks like Deadron code to me, so I imagine it is pretty bullet proof. Are there any modifications that might be relevant?

--Dan
In response to Dan
On 2/24/01 8:29 pm Dan wrote:
This looks like Deadron code to me, so I imagine it is pretty bullet proof.

Thanks for the sentiment -- though I can't help thinking it just means you must not have spent as much time debugging Deadron code as I have!

Since Gilser is experiencing problems with sample code I provided, I would be happy to take a look at it.

Gilser, if you email your project to me ([email protected]), I'll see what's going on.
In response to Deadron
Woops, nevermind! I screwed up, I accidentally changed something I shouldn't have, I just cut out that part and pasted in the original version and it worked fine! My game is coming along well thanks to all you folks out there, thanks a million!
Gilser