ID:158086
 
I am trying unsuccessfully to create a menu in a battle mode, by using a cursor moved by arrow keys. For some reason which I don't fully understand I couldn't use cursor.Move(location(x,y,z)) in client/North(), or in client/South(). help?
If the menu exists on the map, then it would make more sense to use step(cursor, NORTH) than locate().

This is assuming that cursor is a variable defined for clients. If it is defined by mobs, you would need to use mob.cursor instead of just cursor.
In response to Garthor
Garthor wrote:
If the menu exists on the map, then it would make more sense to use step(cursor, NORTH) than locate().

This is assuming that cursor is a variable defined for clients. If it is defined by mobs, you would need to use mob.cursor instead of just cursor.

The cursor is an object, How do I make an object defined for clients?
In response to EternalStudent
client
var/obj/cursor

North()
if(cursor)
step(cursor, NORTH))
else
..()

In response to Garthor
It doesn't work, I must be doing something wrong. Shouldn't I define it in advance? I wrote:

obj/cursor
icon = 'arrow.dmi'

client
var/obj/cursor
North()
if(usr.inCombat)
step(cursor, NORTH)
else ..()
In response to EternalStudent
Code:
obj/cursor
icon = 'arrow.dmi'

client
var/obj/cursor
North()
if(usr.inCombat)
step(cursor, NORTH)
else ..()


Problem description:

Well, it doesn't work. I've tried also cursor.Move(locate()), and I don't understand how to use screen_loc.Can someone help?
In response to EternalStudent
I dont really get what your trying to do. Your code shows that you want the cursor to move along as you do but your also asking about the screen_loc var. Are you trying to show this on the client.screen and have it update when the person moves or are you trying to add it as an actual obj that can be seen by players.
I'm quite new to coding but if you explained what you wanted maybe I could help.

Apoc.
In response to Apocaliptic
I'm trying to create a menu in battle mode. When in battle the arrow keys UP and DOWN should control the cursor and not the player, in order to choose between: Attack, Cast Spell and Run.
In response to EternalStudent
Heres something I put together quite quickly without testing hope it will help you.
Sorry if it doesn't work but hopefully you might be able to create something useful with it.

client
var/obj/cursor
North()
if(usr.inCombat)
var/x=copytext(usr.client.view,1,3)
if(text2num(copytext(cursor.screen_loc,3))==3)
return
if(text2num(copytext(cursor.screen_loc,3))==2)
cursor.screen_loc="[x],3"
if(text2num(copytext(cursor.screen_loc,3))==1)
cursor.screen_loc="[x],2"
else ..()
South()
if(usr.inCombat)
var/x=copytext(usr.client.view,1,3)
if(text2num(copytext(cursor.screen_loc,3))==1)
return
if(text2num(copytext(cursor.screen_loc,3))==2)
cursor.screen_loc="[x],1"
if(text2num(copytext(cursor.screen_loc,3))==3)
cursor.screen_loc="[x],2"
else ..()
Center()
if(usr.inCombat)
for(var/obj/O in cursor.loc)
if(istype(O,/obj/battlehud/attack))
usr.attack()
if(istype(O,/obj/battlehud/spell))
usr.spell()
if(istype(O,/obj/battlehud/attack))
usr.runaway()


mob
proc
battlehud()
for(var/obj/X in typesof(/obj/battlehud))
usr.client.screen+=X
if(istype(X,/obj/battlehud/cursor))
client.cursor=X
obj
battlehud
attack
New()
..()
screen_loc="[copytext(usr.client.view,1,3)],3"
spell
New()
..()
screen_loc="[copytext(usr.client.view,1,3)],2"
runaway\?
New()
..()
screen_loc="[copytext(usr.client.view,1,3)],1"
cursor
icon='arrow.dmi'
pixel_x=-32
New()
..()
screen_loc="[text2num(copytext(usr.client.view,1,3))],3"
In response to Apocaliptic
runtime error: Cannot read null.screen_loc
proc name: North (/client/North)
In response to EternalStudent
You already defined it. You do need to create an actual obj at some point, though. Because you might as well reuse it, we'll just create one and move it around as needed.

client
var/obj/cursor
New()
..()
cursor = new /obj
//instead of giving it an icon, use an image so only we can see it
var/image/I = new(cursor)
src << I

mob/proc/enter_combat()
src.inCombat = 1
client.cursor.loc = wherever it should be
In response to Apocaliptic
You should not be using usr in procs. In the client procs, usr should be replaced with mob (though this is a minor change) and "usr.client" should be replaced with a facepalm and just deleting it.

In battlehud(), usr should be replaced with src (or nothing, as src is the default).

In the New() procs, they should be changed to take an argument, and then use that argument. Like so:

obj
HUD
New(var/client/C)
C.screen += src

client/proc
newhud()
new /obj/HUD(src)
In response to Garthor
Garthor wrote:
You already defined it. You do need to create an actual obj at some point, though. Because you might as well reuse it, we'll just create one and move it around as needed.

client
> var/obj/cursor
> New()
> ..()
> cursor = new /obj
> //instead of giving it an icon, use an image so only we can see it
> var/image/I = new(cursor)
> src << I
>
> mob/proc/enter_combat()
> src.inCombat = 1
> client.cursor.loc = wherever it should be


I usually not that thick-headed, but I didn't understand at all what you did there. First of all I should say that I used the combat mode on a upper layer of the map, and placed the cursor there where it should be to begin with, so it is as to say I created it (I think?).
Second: image? I suppose you don't mean jpg file, right? I'm confused, Why shouldn't I use an icon?
In response to EternalStudent
In response to Garthor
Perhaps this method isn't the best, or the most efficient, but it does work.

client
North()
if(usr.inCombat)
for(var/obj/cursor/O in screen)
switch(O.screen_loc)
if(cursor_attack_loc)
O.screen_loc = cursor_escape_loc
usr.battleAction = "Escape"
if(cursor_escape_loc)
O.screen_loc = cursor_cast_loc
usr.battleAction = "Cast Spell"
if(cursor_cast_loc)
O.screen_loc = cursor_attack_loc
usr.battleAction = "Attack"
else ..()
South()
if(usr.inCombat)
for(var/obj/cursor/O in screen)
switch(O.screen_loc)
if(cursor_attack_loc)
O.screen_loc = cursor_cast_loc
usr.battleAction = "Cast Spell"
if(cursor_cast_loc)
O.screen_loc = cursor_escape_loc
usr.battleAction = "Escape"
if(cursor_escape_loc)
O.screen_loc = cursor_attack_loc
usr.battleAction = "Attack"
else ..()
Center()
if(usr.inCombat)
switch(usr.battleAction)
if("Attack")
//stuff here
..()
if("Cast Spell")
//stuff here
..()
if("Escape")
//stuff here
..()

var
const
cursor_attack_loc = "10,3"
cursor_cast_loc = "10,2"
cursor_escape_loc = "10,1"


Obviously, you shouldn't really have a variable just for the screen_loc, but it gets the point across.

...I can't wait for the hate on this. ^_^
In response to Garthor
OK, I'm starting to get it, but i still have problems with:

mob/proc/enter_combat()
src.inCombat = 1
client.cursor.loc = wherever it should be

You see, I actually called the combat mode using:

turf/grass
icon = 'grass.dmi'
name = "grass"
Enter()
var/x=rand(1,5)
if (x==5)
usr.Move(locate(/area/battle))
usr.inCombat=1
return 1

I can't add client.cursor.loc there because it is an "undefined variable" there
In response to EternalStudent
Strangely enough, "wherever it should be" was a hint for you to actually fill that in with wherever it is supposed to be, not a magical statement that always evaluates to where it should be.
In response to Garthor
Garthor wrote:
>     cursor = new /obj
> //instead of giving it an icon, use an image so only we can see it
> var/image/I = new(cursor)
> src << I


Pardon me if I missed something since I didn't read the whole thread, but you shouldn't need to use a dummy obj for this. /images can be moved around/reattached freely (without needing to be recreated), so all you need to represent the cursor here is the /image itself.
client
var/image/cursor
proc/SetCursor(atom/target)
if(cursor) cursor.loc = target
else cursor = new('cursor.dmi',target)