ID:1841969
 
Ok so I'm trying to code a npc where the buttons text for the buyable items change based on the items put in a list to which when you click the button would set a variable to the item name which when you click the buy button would give you the item and subtract the money. How would I do this?

Hmmm, you... you might want to rephrase or just re-deliever your question. Right now there's not enough punctuation there, and generally its a bit hard to make out what you are talking about at different stages.

1.button text changes to what is in the list
2.clicking button sets variable to what item to give player
3.buy button gives you the set item and subtracts money

get it now?
Mastergamerx wrote:
1.button text changes to what is in the list
2.clicking button sets variable to what item to give player
3.buy button gives you the set item and subtracts money

Mastergamerx wrote:
How would I do this?

I think you just answered your own question.
no i didnt i dont kno how to make the button text change to what is in the list. like how do I code it?
winset(button, set text="???")
winset([mob or client], "[button_id]", "text = sometext")
i need the set text part to be the position in the list
EX: button1's text is set to whatever is the first item in the list
Mastergamerx wrote:
get it now?

Was that patronising? or is it just me reading that wrong... if so i don't understand why, you're looking for help and i was simply asking you to clarify so that i might be able to actually help.

Either-way, since you did somewhat better specify what you were looking for
i need the set text part to be the position in the list
EX: button1's text is set to whatever is the first item in the list

I take the system to be one where as a player scrolls through items in a list, a button's text gets updated accordingly so that it matches the item that is currently focused -or highlighted- within the list.
If the button is pressed, the item referred to by the button's text will be stored as the current item to give to the player (if bought). Then if the buy button gets clicked, that item -accessed as stored within the variable you speak of- gets transferred over.

Does that fit what you're asking?
If so then i have a question. What are you using to display the list of items to the user? Are you using the input() proc?
no the items aren't visibly shown just data as a list which im trying to have each button grab as a array like function for what is assigned like list(apple","orange,"pear") and then the buttons text would be winset(usr,"button",text=[0])so the buttons text would be apple as its in the 0 item on the list then when you press the button it would set the item picked to w/e the [0] item is so when you press buy it gives you that item
I think you might be looking for the interface guide.

http://www.byond.com/docs/ref/skinparams.html

More specifically, "text" parameter.
no im not looking for the interface guide
In response to Mastergamerx
Mastergamerx wrote:
no im not looking for the interface guide


I'm a bit confused what you're looking for then.

You're trying to take a list of /obj, and display the names of those /obj in interface buttons?

You'll probably want to create your own datum for the buttons, if you're having pre-set buttons. Otherwise you'll want to loop through your list of /obj and winset() create buttons at run-time, but that's a bit a hassle really as you'll need to gather pos, size, etc. (Scroll down the skinparams guide to the very bottom.)

Basically, you're question has already been answered a couple times then. Unless what you want is not what we are understanding?

Edit:
My personal opinion, I would just create a grid, then when you click on a buyable /obj in the grid, there will be a label that updates to the name of the obj, a label that shows price, an output that shows item description, and then a button that says "Buy".
all im asking is how do i make it so the button code can set its text to a item in a list based on the items position in the list
well i figured it out but not really in a manner I wanted but now I'm trying to get it to fetch the button being clicked and set the item appropriately
mob
verb
Shopbuttons()
if(winget(usr,"Item1","text='[item1]'"))
selecteditem="[item1]"
world<<"You selected [selecteditem]"
return
if(winget(usr,"Item2","text='[item2]'"))
selecteditem="[item2]"
world<<"You selected [selecteditem]"
return


problem is if i remove the return it'll just go from item 1 to item 2 right after each other im trying to get it to grab what button is being clicked and set it to the proper item how do i fix it
oooh, so this would represent what you're saying right?


While i was working on a snippet example to accompany my suggestion, i unfortunately realised i didn't quite know how to get runtime creation of buttons and so on to work, hopefully someone else can help you on that, but basically the idea was:

mob/Shopkeeper
var
list/itemsToSell = new("Apple","Mango","Pear")// for example's sake.
verb/BuyItems()
set src in view(1) //to show the verb only to mobs up to 1 tile from the shopkeeper
for(var/index = 1 to itemsToSell.len)
if button with id "button[index]" does not exist //could use winexists for this i think
<create a button with id "button[index]"
and text "[itemsToSell[index]]"
and command="buttonClick([itemsToSell[index]])">
else
<show to usr button with id "button[index]"
and text "[itemsToSell[index]]"
and command="buttonClick([itemsToSell[index]])">

Then you could set up the verb that button clicks will activate via 'command' like so:
mob/verb/buttonClick(text)
selectedItem=text
world << "You selected [selecteditem]"

I think... sorry this is just a really rough go at this in my head.

Apologies for this not being an actual solution, but i just spent a few hours trying to find out how to to do the whole dynamic button/window creation stuff, however i just couldn't get it work out at all.
Besides that, i really should be busy doing something else at the moment, so i'm going to have to stop here. Hopefully this is somehow useful though.



yes finally you get what im asking
now can someone please translate his code for the proper interface code for the buttons as i have no clue how to code it as such
In response to Mastergamerx
Mastergamerx wrote:
now can someone please ... code ... as i have no clue how to code it as such


You'll want to look into the skin reference more, as it shows you exactly what you'll want. Again, scroll all the way to the bottom.

Creating or deleting controls at runtime

Controls in a window or pane can be added or deleted at runtime. (Only controls you add at runtime can be deleted.) To create a control, you need to supply a parent parameter with the ID of the window or pane that will hold the control, and type which is one of the available control types.

var/list/params = new
params["parent"] = "mywindow"
params["type"] = "button"
params["text"] = "New button"
params["command"] = "say \"This is a new button.\""
params["pos"] = "10,10"
params["size"] = "80x20"
params["anchor1"] = "0,0"

winset(usr, "newbutton", list2params(params))
The ID of this button will be newbutton, which in full form is mywindow.newbutton.

Note: At the present time, adding a control will not work through the .winset command that can be used in macros or menus, or typed in an input box. Only using the winset() proc inside the program's code will work.

Controls that were added this way can also be deleted again by setting their parent to a blank value.


Or, alternativaly you can check this thread http://www.byond.com/ forum/?post=1425297&hl=create%20button#comment7443016 or LummoxJr's guide http://www.byond.com/forum/?post=33352
In response to Maximus_Alex2003
Yeeeeeeees! woop. Thanks.

I was trying to locate the whole params (i now realise at least, heh) thing for how to generate windows and other controls at runtime, but just couldn't find it... didn't really have the state of mind for a patient perusal of the skinparams doc either, even though i guessed it should be in there somewhere rofl >.< Anyway cheers for the help there. Them Links! (don't think lummox's tut will help so much though, doesn't have anything for runtime generation from what i saw when i checked it earlier... oh, wait, it's just to help him with interfaces right? i gotcha, nvm :D)

Also, with this you really should have pretty much all you need Mastergamerx, if you can understand what my dm code/structured-english hybrid is suggesting then it should be pretty straightforward, using the information Maximus has revealed for creating controls at runtime, to piece it all together and have the setup you're looking for.
In response to Turboskill
Spot on! :)