ID:1492862
 
(See the best response by Rickoshay.)
I have made a simple 'Maze game' but there's a bit of code I can't get to work; I want to change the density of the walls by entering a command under the verb 'Cheats'. Everything works except it won't set the density to 0, heres the extract: http://s1343.photobucket.com/user/rexasarus/media/ byond2_zps07887770.jpg.html

Thanks
Best response
Your usage of if("[k]" == "walls") is wrong. You only need to use if(k == "walls"). K is the variable "walls" is the text, at least that's how I perceive it.

mob
verb
Cheats(K as text)
if(K == "walls")
for(var/turf/wall/T in world)//search for the walls in the world
T.density = 0 //wall density = 0
else
usr<<"incorrect cheat code"


Also just noticed your use of bounds is wrong(Or I think it is, just seen something by kaiocaho). I believe you want to be using bound_x and bound_y. Or the bound_width and bound_height vars. Press F1 in DM to look it up. Kaiochao's post on bounding boxes. http://www.byond.com/forum/?post=1492277#comment8666758

You're also missing ..() in Login(). Most people frown upon the usage of usr in Login as well, so I'd recommend you change that to src.
Thanks :)
Also I had the bounds issue the other day, I was using bound_width and all that but I was told it is far easier to just use the syntax: bounds = "x,y to x,y"
The first 'x,y' being the bottom left corner of the bound and the second 'x,y' being the top right, Try it :)
Cheers, didn't know that myself. Nice to learn something when helping someone.
WAIT!! Don't use that code!! it won't do what you think it will do!!

for(var/turf/wall/T in world)//search for the walls in the world
T.density = 0 //wall density = 0


That means that if you enter that cheat then you and all the other players and NPCs can walk through walls!!


I belive that this is what you want:
mob/var/walk_through_walls=0

mob/verb/Cheats()
var i=input("insert your cheat here:") as text
if(findtext(i,"Walls")==1) //checking if the cheat inserted is "walls"...
world<<"CHEAT ACCEPTED"
src.walk_through_walls =1
else
world<<"SORRY"




turf/wall
density=TRUE
opacity=TRUE
icon='wall.dmi'
icon_state="wall"

Enter(mob/m)
if(m in players)//I made a list so when a player logs in he is added to a list. If the mob is a player then...

if(m.walk_through_walls==0)// if the player's variable walk_through_walls is equal to 0 then...

return 0 // don't let him pass through

else// if the player variable walk_through_walls is equal to 1 then...

return 1 //let him pass through walls YEY :D

With my code the only persons that are able to walk through walls are the players that write the Cheat walls


I hope that i helped


,MistY,
no, he didn't but it wouldn't make sense... Let's imagine that a player writes that cheat ("walls"). Then all the NPCs and players in the game would be able to walk through walls... I mean, a cheat is usually activated for personal benefit, not for everyone's benefit...
hummm...ok, let's assume that it is for a single player game.

,MistY,
Oh totally missed that when i wrote it, I assumed with it being a maze game it would be single player.
In response to Rickoshay
humm yeah...i thought that it would be a multiplayer game but you 2 are probably right...it might be a singleplayer game
It is a single player game however, I have thought of adding NPCs and providing I'm a beginner, everything you guys tell me helps so thanks :)
In response to Rexasarus
oh :) humm anything that u need please tell us :D
In response to Misticone
Will do :P
In response to Rexasarus
yey :D
Misty in the turf could you not use this instead of a list.

        Enter(mob/M)
if(istype(M,/mob/player/))
//etc
Also falcon i told him to put ..() there because if there is no start location, it will return the default action and put them at 1,1,1.

I believe if you didn't overwrite Login() but set mob/icon. You would login at 1,1,1 since you haven't overwritten the default procedure of Login(). Though I understand what you have done with your example.
humm yes, i belive that you could use that. It is funny because in the DM language (and in many other languages) we can do the same thing in lots of different ways :P

You, as a coder, may prefer to solve the problem that way instead of making a list... Your way will work too :D
I'd only really use the list if I had more reasons to, to each their own. :)
I've broken something :L

----------
mob
var
wtw = 0
mob
Login()
loc = locate(/turf/Start)
world << "[src] has entered the castle"
step_size = 8
density = 0
icon = 'mob1.dmi'
icon_state = "Rolling"
bounds = "10,10 to 23,23"
verb
Cheats()
var i = input("Enter cheat") as text
if(findtext(i,"ghost")==1)
usr << "Cheat accepted"
src.wtw = 1
else
usr << "Cheat failed"

obj
step_size = 8
Lamp
luminosity = 3
icon = 'Lamp.dmi'
obj
Door
icon = 'Finish.dmi'
bounds = "1,1 to 32,5"
density = 1


turf
Wall
icon = 'Wall.dmi'
opacity = 1
luminosity = 0
Enter(mob/m)
if(m.wtw == 1)
/turf/Wall
density = 0
else
density = 1

Floor
icon = 'Floor.dmi'
luminosity = 0
Start
icon = 'Start.dmi'
Finish
icon = 'Finish.dmi'
Entered(mob)
world << "Congratulations [usr], you have escaped!"

--------------

This bit works:
Enter(mob/m)
if(m.wtw == 1)
/turf/Wall
density = 0


But it doesn't set the density to 0 and I have no clue what to do...

(and sorry about the code, I don't know how to show an extract in the forums)
Thanks :)
Page: 1 2 3