Topic: Using element IDs

I need to use an ID to use commands with the gui elements. When I get an ID and try to use a command with it, bmax says the command does not exist.
I wanted to have a grid of images and change them as the scrollbar changes.
Here's my code.

'Inventory Window
Local Inventory:IGUIWindow = Gui.addWindow(..
    _RECTI(100 + CNT, 100 + CNT, 400 + CNT, 532 + CNT), ..
    False, ..
    "Inventory", Null, 700)

'Inventory List
Local Row
For Row = 1 To 5
    Local Col
    For Col = 1 To 4
        If (InventoryArray[InvTab.getActiveTab()].length = Row + Col)
            Gui.addImageFromTexture(..
                Video.getTexture("Media/InvItem.tga"), ..
                _POSITION2DI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64)), ..
                True, ..
                Gui.getRootGUIElement().getElementFromId(700), ..
                703 + Row + Col, ..
                InventoryArray[InvTab.getActiveTab()][Row + Col])
        Else
            Gui.addImageFromTexture(..
                Video.getTexture("Media/InvItem.tga"), ..
                _POSITION2DI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64)), ..
                True, ..
                Gui.getRootGUIElement().getElementFromId(700), ..
                703 + Row + Col, ..
                "Empty")
        End If
    Next
Next
'Iventory Scroll Bar
Local InvScroll:IGUIScrollBar = Gui.addScrollBar(False, _RECTI(272, 16 + 64, 292, 360), Inventory, 702)

'Scrolling
If (id = 702 and Gui.getRootGUIElement().getElementFromId(700).isValid() = True)
    Local Row
    For Row = 1 To 5
        Local Col
        For Col = 1 To 4
            Local InvItem:IGUIElement = InvItem = Gui.getRootGUIElement().getElementFromId(703 + Row + Col)
            If (0 = Row + Col)
                InvItem.setText("Used")
                InvItem.setImage("Media/EllipseInfo.tga")
            Else
                InvItem.setText("Empty")
                InvItem.setImage("Media/InvItem.tga")
            End If
        Next
    Next
End If

Re: Using element IDs

greetings smile  which line provided is it erroring on?  and could you paste the error message?

thx.

Re: Using element IDs

i think i figured out what this is and it will actually be fixed in the next version.  getElementFromId() currently returns an IGUIElement.  you need to get the IGUIElement into the actual gui type before you can call the type-specific methods on it.  in the next version of the mod, the return value from getElementFromId() will be the right type, you will just need to cast it.  in the current version though, you will need to call the proper types createFromHandle function, passing in the returned IGUIElement handle.

Re: Using element IDs

I tried what you said but I am having a new problem.
When I try modifying the image elements from IDs they do not accept the changes. I've tested the same code substituting buttons for images and it works correctly.
One thing I noticed is this happens only if the elements are children of another element.

'Create
Gui.addImageFromTexture(..
    Video.getTexture("Media/InvItem.tga"), ..
    _POSITION2DI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64)), ..
    True, ..
    Inventory, ..
    704, ..
    "Empty")

'Change
InvImage = IGUIImage.createFromHandle(Gui.getRootGUIElement().getElementFromId(704).handle)
InvImage.setText("Used")
InvImage.setImage(Video.getTexture("Media/InvUsed.tga"))

Re: Using element IDs

what happens if you use the return value from AddImageFromTexture to change the image?

'Create
InvImage = Gui.addImageFromTexture(..
    Video.getTexture("Media/InvItem.tga"), ..
    _POSITION2DI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64)), ..
    True, ..
    Inventory, ..
    704, ..
    "Empty")

'Change
InvImage.setText("Used")
InvImage.setImage(Video.getTexture("Media/InvUsed.tga"))

6 (edited by HondaDirtBiker 2006-10-09 10:55:18)

Re: Using element IDs

Sorry I should have been more clear. I can't because I create the images and buttons with a loop.
But the Buttons and Scroll bar don't return any information.

This is just the idea of the code.

'Create Inventory List In Inventory Window
Local IDs:Int = 1
Local Row:Int

For Row = 1 To 5
    Local Col:Int
    
    For Col = 1 To 4
        If (InventoryItems[InvTab.getActiveTab()].length => IDs)
            Gui.addImageFromTexture(..
                Video.getTexture("Media/InvItem.tga"), ..
                _POSITION2DI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64)), ..
                True, ..
                Inventory, ..
                703 + IDs, ..
                "Background")
            Gui.addButton(..
                _RECTI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64), 8 + ((Col - 1) * 64) + 64, 64 + 8 + ((Row - 1) * 64) + 64), ..
                Inventory, ..
                703 + 20 + IDs, ..
                InventoryItems[InvTab.getActiveTab()][IDs - 1]).setImage(video.getTexture("Media/InvImage.tga"))
                
                IDs :+ 1
        Else
            Gui.addImageFromTexture(..
                Video.getTexture("Media/InvItem.tga"), ..
                _POSITION2DI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64)), ..
                True, ..
                Inventory, ..
                703 + IDs, ..
                "Background")
            Gui.addButton(..
                _RECTI(8 + ((Col - 1) * 64), 64 + 8 + ((Row - 1) * 64), 8 + ((Col - 1) * 64) + 64, 64 + 8 + ((Row - 1) * 64) + 64), ..
                Inventory, ..
                703 + 20 + IDs, ..
                "Empty").setVisible(False)
            
            IDs :+ 1
        End If
    Next
Next

'Changed if Scrolled in Event Reciever
If (id = 702)
    Local InvButton:IGUIButton
    Local IDs:Int = 1
    Local Scrolled:Int = IGUIScrollBar.createFromHandle(event.getGUIEventCaller().handle, False).getPos()
    Local Row:Int
    Local I:Int
    
    For Row = 1 To 5
        Local Col:Int
        
        For Col = 1 To 4
            If (InventoryItems[0].length => IDs + Scrolled * 4)
                InvButton = IGUIButton.createFromHandle(Gui.getRootGUIElement().getElementFromId(703 + IDs).handle, False)
                InvButton.setVisible(True)
                InvButton.setImage(Video.getTexture("Media/EllipseInfo.tga"))
                InvButton.setText(InventoryItems[0][IDs + Scrolled * 4 - 1])
                
                IDs :+ 1
            Else
                InvButton = IGUIButton.createFromHandle(Gui.getRootGUIElement().getElementFromId(703 + IDs).handle, False)
                InvButton.setVisible(False)
                InvButton.setImage(Video.getTexture("Media/InvItem.tga"))
                InvButton.setText("Empty")
                
                IDs :+ 1
            End If
        Next
    Next
End If

Re: Using element IDs

Alright I think I found the problem.
When I was looking at the API I noticed an option in getElementfromID() to set child searching to true.
Now it returns values. Sweet.
Thanks for your help.

Re: Using element IDs

bah.  i shouldve seen that.  sorry hmm  glad you got it!  i reviewed the inner workings of the code for errors but didnt look at the parameters.  look forward to seeing a project from you someday should you release something public smile