'Wrap around menu' only show X elements of a list

Code needs some explaining but frankly I am too tired :stuck_out_tongue:

My daughter has non verbal autism, and today she used Nick Jr today all by herself using the mouse…

she refuses to use the IPAD to communicate, or physical pecs icons…

so I am making a PEC’s system using Nick Jr interface… (www.nickjr.com)

this is to replicate the ‘show’ icons
next I will have a image for each icon ‘Places’, ‘Things’, ‘Feelings’ , ‘actions’ etc. ‘misc’

clicking a category will bring up options in each, cliking a option adds that objects word to a string.

like people->I , feelings->want, misc->to, actions ->go , misc->to , places->park

click say -> I want to go to park

basically move items a direction,
if a icon is too far over delete it,
add a new icon on the other side that has a value (1 less then min or 1 more then max) off ‘inactive icon list’ depending which way you moved the icons


import bge



def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    LeftMouse = cont.sensors['LeftMouse']
    Right = cont.sensors['Right']
    Left = cont.sensors['Left']
    
    if 'catagories' not in own:
        own['catagories']=[]
        for objects in own.scene.objects:
            if 'I' in objects:
                own['catagories'].append([objects.children[0]['Text'],objects['I'],objects])
                if objects not in own.children:
                    objects.endObject()
        own['catagories']=sorted(own['catagories'], key=lambda tup: tup[1])  
        own['Total']=str(own['catagories'])              
    else:
        min=len(own['catagories'])
        max=0
        maxOb=""
        index=0
        left = 0
        leftOb=""
        right=0
        rightOb=""
        for objects in own['catagories']:
            if not objects[2].invalid:
                if objects[2].worldPosition.y<left:
                    left=objects[2].worldPosition.y
                    leftOb=objects[2]
                if objects[2].worldPosition.y>right:
                    right=objects[2].worldPosition.y
                    rightOb=objects[2]    
                    
                if objects[2]['I']>max:
                    max=objects[2]['I']
                    maxOb=index
                if objects[2]['I']<min:
                    min=objects[1]
                    minOb=index
                        
            index+=1        
                
                
            
        if Left.positive and LeftMouse.positive:
            for objects in own['catagories']:
                if not objects[2].invalid:
                    objects[2].worldPosition.y-=.05
                    if objects[2].worldPosition.y<-7:
                        objects[2].endObject()
                        print(max)
                        next= max+1
                        print(next)
                        
                        nonExist=[]
                        for objects in own['catagories']:
                            if objects[2].invalid:
                                nonExist.append(objects)
                        nonExist = sorted(nonExist, key=lambda tup: tup[1])  
                        Go=0
                        for objects in nonExist:
                            
                            if next==objects[1]:
                                added = own.scene.addObject('Icon',own,0)
                                added.worldPosition= rightOb.worldPosition+own.worldOrientation.col[1]*3
                                own['catagories'][objects[1]-1][2]=added
                                added['I']=objects[1]
                                added.children[0]['Text']=objects[1]
                                Go=1
                                
                        if Go==0:
                            added = own.scene.addObject('Icon',own,0)
                            added.worldPosition= rightOb.worldPosition+own.worldOrientation.col[1]*3
                            own['catagories'][nonExist[0][1]-1][2]=added
                            added['I']=nonExist[0][1]
                            added.children[0]['Text']=nonExist[0][1]
                            
        elif Right.positive and LeftMouse.positive:                         
            
            for objects in own['catagories']:
                if not objects[2].invalid:
                    objects[2].worldPosition.y+=.05
                    if objects[2].worldPosition.y>7:
                        objects[2].endObject()
                        
                        print(min)
                        next= min-1
                        print(next)
                        
                        nonExist=[]
                        for objects in own['catagories']:
                            if objects[2].invalid:
                                nonExist.append(objects)
                        nonExist = sorted(nonExist, key=lambda tup: tup[1])  
                        Go=0
                        if next>0:
                            for objects in nonExist:
                                
                                if next==objects[1]:
                                    added = own.scene.addObject('Icon',own,0)
                                    added.worldPosition= leftOb.worldPosition+own.worldOrientation.col[1]*-3
                                    
                                    own['catagories'][next-1][2]=added
                                    
                                    added['I']=objects[1]
                                    added.children[0]['Text']=objects[1]
                                    Go=1
                                    
                            if Go==0:
                                
                                added = own.scene.addObject('Icon',own,0)
                                added.worldPosition= leftOb.worldPosition+own.worldOrientation.col[1]*-3
                                num =nonExist[-1][1]
                                print(num)
                                own['catagories'][num-1][2]=added
                                added['I']=nonExist[-1][1]
                                added.children[-1]['Text']=nonExist[-1][1]
                        else:
                            added = own.scene.addObject('Icon',own,0)
                            added.worldPosition= leftOb.worldPosition+own.worldOrientation.col[1]*-3
                            num =nonExist[-1][1]
                            own['catagories'][num-1][2]=added
                            added['I']=nonExist[-1][1]
                            added.children[-1]['Text']=nonExist[-1][1]
                                         
                                 
                                       
                    
        list=[]            
        for ob in own['catagories']:
            if ob[2].invalid:  
                list.append(ob[1])
                         
        own['Total']=str(list)        
        own['read2']=str(min)            
main()



Attachments

WrapListIcons.blend (705 KB)

This is honestly amazing. but my question is, wouldnt whatever logic bricks you put on any individual button be replaced as soon as it goes wraps around once? how would you remidy that? the only way I could think to do it is to have the ICON be linked to python and then do everything through python.

Just have strings stored in the item, and use a dictionary of python commands to call the command.


import bge
cont = bge.logic.getCurrentController() 
own = cont.owner 
mouseOver = cont.sensors['MouseOverAny'] 
leftMouse = cont.sensors['LeftMouse'] 


def function():
    pass

def function2():
   pass


Dictionary = { string:function, string2:function2} 


def main():
    if mouseOver.positive and leftMouse.positive:
        String = mouseOver.hitObject['String']


        Command = dictionary[string] 
        Command()
main() 


Thank you! sorry it took me so long to get back to you. I’ll give it a try soon. Just wanted to make sure, would you be alright with me using this in a game im currently making?

yeah, it’s fine.