Shop System Issue
by Andrew Patterson · in Torque Developer Network · 03/16/2012 (1:53 pm) · 13 replies
Hello,
I am trying to make a simple shop system. However when I click on the item in the list, it never shows the value it supposed to show. In fact it dosen't show anything.
function ShopItems::PopulateList(%this)
{
ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
if(ItemList.getSelectedItems([$STIMPACKS,%i]))
{
buyAmount.setValue("10");
}
}
}
What am I doing wrong in this code?
I am trying to make a simple shop system. However when I click on the item in the list, it never shows the value it supposed to show. In fact it dosen't show anything.
function ShopItems::PopulateList(%this)
{
ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
if(ItemList.getSelectedItems([$STIMPACKS,%i]))
{
buyAmount.setValue("10");
}
}
}
What am I doing wrong in this code?
About the author
#2
03/17/2012 (10:58 am)
Yes I'm sure I have. I'll post my full code just to make sure.moveMap.bindCmd(keyboard, "insert", Shop @ ".toggleMenu();", "");
$STIMPACKS = 0;
$WEAPONS = 1;
$ACCESSORIES = 2;
$Stim[$STIMPACKS,0] = "Smallstimpack";
$Stim[$STIMPACKS,1] = "Mediumstimpack";
$Stim[$STIMPACKS,2] = "Largestimpack";
function Shop::toggleMenu(%this)
{
if(!%this.isAwake())
{
Canvas.pushDialog(%this);
}
else if(!ShopItems.isAwake())
{
Canvas.popDialog(%this);
}
}
function Shop::buy(%this)
{
if(!ShopItems.isAwake())
{
ShopItems.initialize();
ShopItems.PopulateList();
Canvas.pushDialog(ShopItems);
}
textBuy.visible = true;
textSell.visible = false;
}
function Shop::sell(%this)
{
if(!ShopItems.isAwake())
{
ShopItems.initialize();
Canvas.pushDialog(ShopItems);
}
textBuy.visible = false;
textSell.visible = true;
}
function ShopItems::initialize(%this)
{
%dialogBox = ShopItems.findObjectByInternalName("ShopItemWin");
%Items = %this.findObjectByInternalName("Items");
%totaltext = %this.findObjectByInternalName("totaltext");
%totalitemtext = %this.findObjectByInternalName("totalitemtext");
%amountbuy = %this.findObjectByInternalName("amountbuy");
%amountsell = %this.findObjectByInternalName("amountsell");
}
function ShopItems::PopulateList(%this)
{
ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
if(ItemList.getSelectedItems([$STIMPACKS,%i]))
{
buyAmount.setValue("10");
}
}
}
function ShopItems::SelectItems(%this)
{
}
function ShopItems::confirm(%this)
{
}
function Shop::exit(%this)
{
Canvas.popDialog(%this);
}
function ShopItems::cancel(%this)
{
Canvas.popDialog(%this);
}
#3
then echo out ItemList.getSelectedItems([0,0]);
and see if you are populating it.
03/17/2012 (11:11 am)
cut it down in to chunks outside of your functions, and see if its doing what it's meant to..ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
if(ItemList.getSelectedItems([$STIMPACKS,%i]))
{
buyAmount.setValue("10");
}
}then echo out ItemList.getSelectedItems([0,0]);
and see if you are populating it.
#4
03/17/2012 (11:14 am)
Well the item list is being populated with items. What I mean is that when you select an item from the list, the value it supposed to display in the buy text section dosen't show.
#5
add:
What do you get in the console?
03/17/2012 (5:06 pm)
after:buyAmount.setValue("10");add:
buyAmount.echo();
What do you get in the console?
#6
setValue() - (int value, int index) Set the value of the array element at the submitted index
Don't you need a value, and an index number?
03/17/2012 (5:09 pm)
Also withsetValue() - (int value, int index) Set the value of the array element at the submitted index
Don't you need a value, and an index number?
#7
I get these errors in the console. Wrong number of parameters for setValue(), I also get the error, no return value.
03/17/2012 (5:30 pm)
function ShopItems::PopulateList(%this)
{
ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
buyAmount.setValue("10",%i);
buyAmount.echo();
}
}I get these errors in the console. Wrong number of parameters for setValue(), I also get the error, no return value.
#8
03/18/2012 (12:58 pm)
I'll have my dev environment setup again next week, so I'll take a look then. Unless someone else comes up with a solution for you.
#9
03/19/2012 (7:51 pm)
Thanks for your help.
#10
function ShopItems::PopulateList(%this)
{
ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
buyAmount.setValue("10",%i);
buyAmount.echo();
}
return buyAmount;
}
and the
buyAmount.setValue("10",%i);
if you say it has the wrong amount of parameters then that means it should only have 1 value so your %i shouldn't be there.
Something like this
buyAmount.setValue("10");
03/25/2012 (5:33 pm)
not sure but something I would tryfunction ShopItems::PopulateList(%this)
{
ItemList.clearItems();
for(%i = 0; %i < 3; %i++)
{
ItemList.addItem($Stim[$STIMPACKS,%i]);
buyAmount.setValue("10",%i);
buyAmount.echo();
}
return buyAmount;
}
and the
buyAmount.setValue("10",%i);
if you say it has the wrong amount of parameters then that means it should only have 1 value so your %i shouldn't be there.
Something like this
buyAmount.setValue("10");
#11
03/25/2012 (6:54 pm)
Thanks, but it dosen't work the way I want it too. I need it so that when the user clicks on an item in the list, it will display the buy price of the selected item.
#12
%Price = ItemList.getSelectedItems([$STIMPACKS,%i]
then in the gui have the text = %Price,
Sorry haven't got the torque engine yet still in demo.
03/25/2012 (7:02 pm)
Maybe something like,%Price = ItemList.getSelectedItems([$STIMPACKS,%i]
then in the gui have the text = %Price,
Sorry haven't got the torque engine yet still in demo.
#13
05/23/2012 (12:20 am)
Well, if you are using a Text List Control, I think there is a method like so:function someTextListCtrl::onSelect(%this,%a,%b,%c)
{
//Echo what each of the arguments are because I don't know off hand.
}
Torque Owner Jules
Something2Play