Reputation: 359
My code selects items from a comboBox by its index number then assigns a specific byte to each item. For this I am using the If statement and am having to repeat it so many times.
I know how to use loops very basically but I haven't got a clue how to do it when each item needs a different value assigned to it.
if (weaponcamCombo.SelectedIndex == 0)
{
PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0A });
}
if (weaponcamCombo.SelectedIndex == 1)
{
PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0B });
}
if (weaponcamCombo.SelectedIndex == 2)
{
PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0C });
}
As you see a specific byte is assigned to each item, I was wondering how I would still do this but in a loop?
Thanks
Upvotes: 0
Views: 117
Reputation: 13495
You might be able to create a function that sets the memory and then just call it with an index.
public void SetMemory(int index)
{
if(index >= 0)
{
PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { (0x0A + index)});
}
}
Then call it like this:
SetMemory(weaponcamCombo.SelectedIndex);
Upvotes: 0
Reputation: 15354
Add weaponcamCombo.SelectedIndex
to 0x0A
if(weaponcamCombo.SelectedIndex>-1)
{
PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0A + weaponcamCombo.SelectedIndex });
}
OR use a lookup table (in fact an array)
var values = new byte[]{0x0f,0x6a};
if(weaponcamCombo.SelectedIndex>-1)
{
PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { values[weaponcamCombo.SelectedIndex] });
}
Upvotes: 2