ID:139898
 
This is the main code where I am getting confused logic-wise:
obj
skillcards
icon_state = "normal"
layer = 6//Give it a layer higher than anything else
MouseEntered()//When the mouse enters
icon_state = "mouseover"//change the icon
MouseExited()//When the mouse exits
sleep(1)//Wait 1/10 of a second
icon_state = "normal"//change the icon
s_one
screen_loc = "1,1"//The X and Y Locations on screen
s_two
screen_loc = "2,1"
s_three
screen_loc = "3,1"
s_four
screen_loc = "4,1"
s_five
screen_loc = "5,1"
s_six
screen_loc = "6,1"
s_seven
screen_loc = "7,1"
s_eight
screen_loc = "8,1"
s_nine
screen_loc = "9,1"
s_zero
screen_loc = "10,1"



obj
test_objects
layer = 7
var/neverclicked
var/mob/player/P
var/atom/A
Click()
src.P = usr
if(!neverclicked)
neverclicked = 1
switch(alert("Would you like to macro this?",,"Yes","No"))
if("Yes")
var/number = round(input(usr,"Which key would you like to macro this to? Enter a number between 1 and 10 (Decimals will be rounded down).","Input") as num)
if(number < 1||number > 10)//Don't allow them to enter an improper value
usr << "Value entered was too small/large. Please enter a value between 1 and 10."
neverclicked = null
return
else
usr << "[number] = number"//Test, Just in case
usr << "[P.current_set_list] = current_set_list"//Test, Just in case
if(P.current_set_list == 1)
P.setmacros_1[number] = null//Make that # in the list null
// var/setup = P.screenobjects[number]//Define a variable as object in list
// setup.overlays += src





// P.setmacros_1[number] += //Add the clicked overlay
// var/overlayadd = P.screenobjects[number]
// overlayadd.overlays+=P.setmacros_1[number]

/* else if(P.current_set_list == 2)//Redundant
P.setmacros_2[number] -= A
P.setmacros_2[number] += A
else if(P.current_set_list == 3)
P.setmacros_3[number] -= A
P.setmacros_3[number] += A
else if(P.current_set_list == 4)
P.setmacros_4[number] -= A
P.setmacros_4[number] += A
else if(P.current_set_list == 5)
P.setmacros_5[number] -= A
P.setmacros_5[number] += A
else if(P.current_set_list == 6)
P.setmacros_6[number] -= A
P.setmacros_6[number] += A*/

neverclicked = null
if("No")
neverclicked = null
else if(neverclicked)
usr << "You currently are already setting up a macro."
else
usr << "<big>Error.</big>"

// if("No")
// return
purple
icon_state = "purple"
blue
icon_state = "blue"
green
icon_state = "green"
red
icon_state = "red"
orange
icon_state = "orange"

mob/player/var/tmp/list/testOBJS = list(new/obj/test_objects/purple,new/obj/test_objects/blue,new/obj/test_objects/green,new/obj/test_objects/red,new/obj/test_objects/orange)
//This list is added to your contents when you login, under Unrelated.dm


mob/player/var/list/setmacros_1[10]//These lists are used to add the icon overlays
mob/player/var/list/setmacros_2[10]
mob/player/var/list/setmacros_3[10]
mob/player/var/list/setmacros_4[10]
mob/player/var/list/setmacros_5[10]
mob/player/var/list/setmacros_6[10]

mob/player/var/list/macrocommand_1[10]//These lists are used to set the macros (Didn't do yet)
mob/player/var/list/macrocommand_2[10]
mob/player/var/list/macrocommand_3[10]
mob/player/var/list/macrocommand_4[10]
mob/player/var/list/macrocommand_5[10]
mob/player/var/list/macrocommand_6[10]



mob/player/var/tmp/list/screenobjects = list(new /obj/skillcards/s_one,new /obj/skillcards/s_two,new /obj/skillcards/s_three,new /obj/skillcards/s_four,new /obj/skillcards/s_five,new /obj/skillcards/s_six,new /obj/skillcards/s_seven,new /obj/skillcards/s_eight,new /obj/skillcards/s_nine,new /obj/skillcards/s_zero)
//This list is of the objects that are added to the client's screen upon login

mob/player/var/tmp/current_set_list = 0
//The set list being used Variable


var/tmp/SM = 0//Used in Scroll_List() proc to set where setmacros_# is being manipulated
var/tmp/SO = 0//Used in Scroll_List() proc to set which OBJ in screenobjects is getting an overlay

mob/player/var/tmp/Allowed = 1//Variable to check whether Scroll_List() is currently being used or not

mob/player/proc/Scroll_List()
if(Allowed)
Allowed = null
usr << "In process . . ."

current_set_list++

if(current_set_list<=6)//We want the number to be between 1 and 6
current_set_list = 1//If bigger or already equals 6, set to 1

if(SM>10&&SO>10)
for(SM>10&&SO>10)
usr << "<font color = red>Set list = [current_set_list], For SM>10&&SO>10, SM = [SM], SO = [SO]</font>"//Test, Just in case
SM++
SO++
usr << "<font color = blue>Set list = [current_set_list], SM++, SO++, SM = [SM], SO = [SO]</font>"//Test, Just in case

screenobjects[SO]-=overlays

if(current_set_list == 1)//Whatever the variable is
screenobjects[SO]+=setmacros_1[SM]//add the object, to the object SO in screenobjects, on the list spot of SM
else if(current_set_list == 2)//This part is redundant, but I don't know of a better way.
screenobjects[SO]+=setmacros_2[SM]
else if(current_set_list == 3)
screenobjects[SO]+=setmacros_3[SM]
else if(current_set_list == 4)
screenobjects[SO]+=setmacros_4[SM]
else if(current_set_list == 5)
screenobjects[SO]+=setmacros_5[SM]
else if(current_set_list == 6)
screenobjects[SO]+=setmacros_6[SM]
else
usr << "<big>Error.</big>"


usr << "<font color=purple>Set list = [current_set_list], SM = [SM], SO = [SO]S</font>"//Test, Just in case
else if(SM<=10||SO<=10)
Allowed = 1
usr << "<font color = orange>Complete. Allowed = [Allowed]. Set list = [current_set_list]</font>"//Test, Just in case
else if(!Allowed)
usr << "Currently not allowed. Allowed = [Allowed]"
else
usr << "<big>Error.</big>"//Test, Just in case


Problem description:
I am trying to, in the empty If statement, have an object in the setmacros list be null. Then, to add an object in that spot. Then, to take the object from that spot in the list and add it to an overlay from an object in the same spot in the screenobjects list.


You can download a complete version of the demo here:

http://quickupload.net/i65vszthjk1e/ Macro_Demo_src-quickupload.net.zip.html

Thanks for any help!

It's not clear which if() statement you're referring to; none of them appear to be empty.

I do see several design flaws which should probably be addressed first. There is no apparent need for 10 subtypes under /obj/skillcards, when a single type and a var will suffice. You have six different lists each for macros and their definitions, which suggests you'd be better off going with a multidimensional list [6][10] or with a single combined list [60]. Without knowing the purpose of the system I'm not sure which way to steer you, but when you have a ton of vars that have the same purpose like macro1, macro2, macro3, etc., that's a red flag that your design needs a rethink.

Also, just so you know it is bad practice (for readability) when using // comments not to put some spacing between the rest of the line and the comment. A tab is usually the preferred choice.

// Wrong
a+=5//increment a

// Right
a+=5 // increment a


Lummox JR
In response to Lummox JR
Ok, my bad about the 'empty' part, it actually was supposed to be this section:

                       else
usr << "[number] = number"//Test, Just in case
usr << "[P.current_set_list] = current_set_list"//Test, Just in case
if(P.current_set_list == 1)
P.setmacros_1[number] = null//Make that # in the list null
// var/setup = P.screenobjects[number]//Define a variable as object in list
// setup.overlays += src


that I was lost for with logic on how to properly null the overlay on the card(obj) in the list, save an 'overlay'(obj) in another list, and add the 'overlay'(obj) from the list it was saved in as an overlay to the card(obj) in the list.

I'll heed your advice and try to fix the design flaws.

Thanks for helping.

(I also mixed up some of my greater than and less than symbols.)



The purpose of the system is to have six different sets of verbs with sets of overlays for the objects on the screen, and to be able to 'scroll' through them on runtime.
In response to Lummox JR
I am having confusion with how to add an overlay to a specified object in a list. I tried two different methods, which are commented out under the set_macros() proc.

Also, with having a type and a variable to set up the ten different skill-cards instead of defining them...well, I don't understand how to do that! The reason being that I would not know how to define the separate icon states for each one.

Here is the current code:
#define Move_Up 5 //These are just used to make it an easier concept to have
#define Move_Down 10 //numbers set for a variable, but instead you can use text that equals those numbers

world //Basic world setup to test demo
maxx = 10
maxy=10
maxz=1

client/view = 7 //Your view

atom/icon = 'Icons.dmi' //Icon setting for objs,areas,turfs,mobs is Icons.dmi

world/mob = /mob/player //Set the world's mob

mob/player/Login()
Maximize() //Maximize your screen
client.screen+=cardobjects //Add a list of objects

mob/player/Stat()
statpanel("Iventory",usr.contents) //Have a statpanel that shows the client's mob's contents


var/tmp/Never //Set up a variable for the verb
mob/player/verb/True_False_Checker() //This verb is just an example for the NOT operator
set hidden = 1
if(Never) //Check if it is true
Never = null //Setting to null is like setting to false
usr << "Never = False(null)"
else if(!Never) //Check if it is false
Never = 1 //Setting to 1 is like setting to true
usr << "Never =True(1)"

mob/proc/Maximize()
winset(src,"window1", "is-maximized=true") //Maximize your window

////////////////////////////////////////////////////////////////////////////////////////////////////////////
obj
skillcards
icon_state = "normal"
layer = 6 //Give it a layer higher than anything else
MouseEntered() //When the mouse enters
icon_state = "mouseover" //change the icon
MouseExited() //When the mouse exits
sleep(1) //Wait 1/10 of a second
icon_state = "normal" //change the icon
s_one
screen_loc = "1,1" //The X and Y Locations on screen
s_two
screen_loc = "2,1"
s_three
screen_loc = "3,1"
s_four
screen_loc = "4,1"
s_five
screen_loc = "5,1"
s_six
screen_loc = "6,1"
s_seven
screen_loc = "7,1"
s_eight
screen_loc = "8,1"
s_nine
screen_loc = "9,1"
s_zero
screen_loc = "10,1"

obj
buttons
var/mob/player/P
UP
icon_state = "up"
Click()
if(P.Allowed)
P.Allowed = null
direction = Move_Up//set variable value(defined at top)
P.set_macros()
DOWN
icon_state = "down"
Click()
if(P.Allowed)
P.Allowed = null
direction = Move_Down//set variable value(defined at top)
P.set_macros()

obj
test_objects
var/neverclicked
var/mob/player/P
DblClick()
if(!neverclicked)
neverclicked = 1
switch(alert("Would you like to macro this?",,"Yes","No"))
if("Yes")
var/number = round(input(usr,"Which key would you like to macro this to? Enter a number between 1 and 10 (Decimals will be rounded down).","Input") as num)
if(number < 1||number > 10)//Don't allow them to enter an improper value
usr << "Value entered was too small/large. Please enter a value between 1 and 10."
neverclicked = null
return
else

layer = 7
purple
icon_state = "purple"
blue
icon_state = "blue"
green
icon_state = "green"
red
icon_state = "red"
orange
icon_state = "orange"



var/list/testOBJS = newlist(/obj/test_objects/purple,/obj/test_objects/blue,/obj/test_objects/green,/obj/test_objects/red,/obj/test_objects/orange)
//This list is added to your contents when you login, under Other.dm

mob/player/var/list/grid_objoverlay[6][10] //Multi-Dimensional list for icon overlays (6 sets of 10)

mob/player/var/list/grid_macrocommand[6][10] //Multi-Dimensional list for macro commands (6 sets of 10)


var/list/cardobjects = newlist(/obj/skillcards/s_one,/obj/skillcards/s_two,/obj/skillcards/s_three,/obj/skillcards/s_four,/obj/skillcards/s_five,/obj/skillcards/s_six,/obj/skillcards/s_seven,/obj/skillcards/s_eight,/obj/skillcards/s_nine,/obj/skillcards/s_zero)
//This list is of the objects that are added to the client's screen upon login

mob/player/var/tmp/current_set_list = 1 //The value of the lists you are using

mob/player/var/tmp/Allowed = 1 //Variable to check whether Scroll_List() is currently being used or not

var/direction //This is used to tell list_iteration whether to increase or decrease(Move_Up,Move_Down)

mob/player/proc/set_macros()
list_iteration()
for((var/a == 0)<10)
var/b = 1
var/c = 1
// cardobjects[b].overlays = null
// cardobjects[b].overlays+=grid_objoverlay[current_set_list][c]

/* var/CO = cardobjects[b]
CO.overlays -= var/atom/A
var/OO = grid_objoverlay[current_set_list][c]
b++
c++
a++
*/


mob/player/proc/list_iteration()

if(direction==Move_Up)
current_set_list++
if(current_set_list>6) //If bigger than 6, make it 1
current_set_list = 1

else if(direction==Move_Down)
current_set_list--
if(current_set_list<1) //If less than 1, make it 6
current_set_list = 6
In response to Darkjohn66
Darkjohn66 wrote:
I am having confusion with how to add an overlay to a specified object in a list.

It's a rather simple manner, but of course you're confused with it. This is unfortunately a common condition here. That's how it is when you go on programming without first really getting to know the language and its syntax, how to work with it and other tidbits.
You seem to skip the learning-on-your-own procedures and then you program with your limited knowledge and experience of working the basics, so it's only natural that you'd regularly run into problems, even with simple things (such as setting a variable to the correct value type or accessing something from a list) that you're supposed to be far beyond, at this point.
You're better than you used to be, but nevertheless you will still inevitably fall into holes in your knowledge such as the distinction between a type path and object instance, basic list handling, etc. And the ability to see better program/feature design also requires being very comfortable with the language.

Yes, you can go on making forum topics whenever you stumble into a hole and have your code patched up or your hole hopefully filled, but that's not very efficient or all-around-helpful. It's not the forumgoers' job to tutor people, there are reusable resources for that. Forum help is supposed to be only a once in a while additive, ideally a last resort.

I tried two different methods, which are commented out under the set_macros() proc.

    cardobjects[b].overlays = null


You can't do this, mainly because this syntax doesn't exist in DM. Some other languages allow this because an array can only contain values of a single type, but in DM lists are really versatile and can contain mixed values of any type.
Anyway, this kind of syntax doesn't exist in DM, hence you have to first store a reference to the object in the list in a var, then use said var when accessing the object's properties. Which is what you have in the next block of code.
        var/CO = cardobjects[b]
CO.overlays -= var/atom/A


2 problems here. First, you can't access CO.overlays because the compiler isn't certain that whatever is in CO is supposed to have an overlays var, and will give you an error with the aim of preventing you from making a logic error or slipping up. This is the . operator's compile-time error checking. The : operator skips most of this checking, so switching to it will fix this problem, but it's highly frowned upon as you want to keep the error checking as its purpose is to help you.
When declaring the CO var, you need to define it as of a type that has an "overlays" var. Such as /mob, but a less specific type such as /atom will also work. Note that this var's-defined-type is a compile-time-only property that's mainly used for this very error checking and not much else. In other words, it doesn't affect the var at runtime, or affect its value at all.

The bigger problem is the right-side of the -= operator. Here you simply made up your own imaginary syntax and expected it to do what you want, there's not really much more to be said about it.
In response to Kaioken
Thanks Kaioken. That really helped.

Also. what do you think I should go about doing? I mean, I've made a few simple games, I've read many Byond articles, and I've read the guide. I don't use ripped sources. I read the work of people such as Lummox, Jtgibson, even you!, but I am still having trouble grasping some more complicated concepts. I guess I need to think more logic wise then, "How do I program this in DM?". Because, like you said, a randomly defined variable in a proc cannot have an overlay added to it. It needs to be something that can.

Well, I guess I will just keep on attempting to learn the best I can, if you have any suggestions please throw them at me!

Thanks again.