ID:1747486
 
(See the best response by Mightymo.)
Code:
obj/overlay
number
icon = '1.dmi'

mob/player/Wear_One()
for(var/obj/shooter/O)
O.overlays += /obj/overlay/number
world << "test"


Problem description:Ok so Im trying to make a counter for my rock training that will display the number of rocks you catch on an turf. The above is me testing the overlay on an obj.

The hardest part I need help with is finding how to get a several digit number to display in order. For example

I've caught 1234 rocks. I will give an x,y,z for the number 4 to overlay. Then can give instructions for the number 3 to overlay the turf to the left of that. Then so on and so on.

Im not sure how to extract and handle the caught number of rocks so that I can tell it which number to display and where.

I dont want All the code. I just need help to learn how this works. Code snippets or commands I should refer too. Thanks for all your help :)

Best response
You could use num2text() to convert to a string, and then iterate through each number. After each iteration, increase the x value, so that you know where to put the next one.

Have you already decided against using maptext? That would be easier, although I suppose it may not fit your needs.
I didn't know about maptext. I'll look into that. I wasn't sure what commands were available to me to make this the easiest. Thanks for your help again Mightymo. I'll look into this and hopefully update the thread with questions or results lol. Let me know if there is any other commands I might want to look into. Thanks
I can't seem how to use num2text to get each digit and its placement out of a number.

I used it as a verb to learn more about the command

numtotext()
var/T = num2text(caught,1)
world << "T [T]"


I know if I change the 2nd argument it will give me a scientific number.

If I am getting the number 1234. How do I get num2text to tell me 2 is in the hundreds spot for example? I think I can do the rest of my code but I need a command that will tell me what number is in which spot so I can display it the way I'd like. Thanks for any help in advance.
var/num = 1234
var/numText = num2text(num)
world << copytext(numText,2,3)


If you want the hundreds place specifically, perhaps consider using negative indices or using lentext().
This helped me a lot and I think I will be able to implement what im trying to do soon.

One issue im running into and this is probably an easy one.

I want to add the overlay to an obj near by. This is what I've tried.

var/one = copytext(numText,1,2)
for(var/turf/wall1/O)
O.overlays += /obj/overlay/one
// I've also tried
//O.overlays += /obj/overlay/[one]


What am I missing to make it choose the path depending on the var "one". How do I insert that into the /obj/overlay/
I would highly recommend not doing that. A considerably better idea would be to use one icon that has multiple states, in which case a number could be directly translated into an icon_state. If you really want to do it this way, use text2path(). Note that you'll have to translate the numbers to the words.
You probably are going to laugh... but here is how I did it. I know its not the cleanest code but so far I have found a bug and it does what I want it to.

If you find something "seriously" wrong with this code please let me know with a little advice as to the direction I need to take the fix it.

obj/proc/TrainingCounter()
var/cheating = caught - missed // keeps players from standing still in training
var/numText = num2text(caught-missed) // number goes down if they miss a rock
var/four = copytext(numText,4,5)
var/three = copytext(numText,3,4)
var/two = copytext(numText,2,3)
var/one = copytext(numText,1,2) // turns number into text for later
var/length = lentext(caught)
if(cheating <= 0)
caught = 0
missed = 0
return
if(length == 1) // figures out how many digits in number.
goto step1
if(length == 2)
goto step2
if(length == 3)
goto step3
if(length == 4)
goto step4
var/turf1 = text2path("/obj/overlay/number[one]") // picks the correct icon depending on digit recieved
var/turf2 = text2path("/obj/overlay/number[two]")
var/turf3 = text2path("/obj/overlay/number[three]")
var/turf4 = text2path("/obj/overlay/number[four]")
step4
for(var/turf/wall1/D) //wall the numbers appear over
if(four)
D.overlays = 0
D.overlays += turf4
step3
for(var/turf/wall2/C)
if(three)
C.overlays = 0
C.overlays += turf3
step2
for(var/turf/wall3/B)
if(two)
B.overlays = 0
B.overlays += turf2
step1
for(var/turf/wall4/A)
if(one)
A.overlays = 0
A.overlays += turf1


Thanks Mightymo for all your help!

Here a link to a Youtube video I uploaded on what it looks like.

https://www.youtube.com/watch?v=zhsXS6UOQoU
Your main problem is incorrect use of goto. This is why people recommend that you don't use goto. I'm not certain how it is even working for you considering that you are skipping the variable declarations. You are also checking the length of the wrong number. Beyond that, you are doing a lot of excess programing.


This is uncompiled, I used a passed turf and any turf rather than your loop and specific walls, and I simplified down to using one icon, but I hope you get the idea.
obj/proc/TrainingCounter(var/turf/t)
var/cheating = caught - missed // keeps players from standing still in training
var/numText = num2text(cheating) // number goes down if they miss a rock
if(cheating <= 0)
caught = 0
missed = 0
return
for(var/i=1;i<5;i++)
var/num = copytext(numText,i,i+1)
if(!t || !num) break;
t.overlays = null
var/overlay/number/oNum = new()
oNum.icon_state = num
t.overlays += oNum
t = locate(t.x+1,t.y,t.z)

It would probably be better to keep the overlay as a variable rather than removing all overlays and replacing them. Also, it looks like if the cheating branch is taken, the number will stay at one, although I'm not sure how you've handled that elsewhere.
Unfortunately I don't understand everything in the above code yet. I'm not going to copy and paste it as I want to understand what I'm putting in my code. Secondly, as you said not knowing how I handled my code elsewhere in my game it might cause issues.

However I'm going to keep coming back to this thread and trying to implement your suggestions as I get to understand them more. Thanks again for your help.
If there is something that you don't understand, just ask. This code is unlikely to be largely affected by or affect other code, so it isn't too big of an issue.