Forum Archive

Need hellp with Ui.View.close method

Bjucha

Hello I have added a ui.view on my scene that is displayed when my game starts, and at the same time the Scene.Paused = True condition is activated. Here is The problem I want a button that when presse closes the ui.view using ui.view.close and starts the scene, however I cant get the ui.view.closee to work. I always get that main_view (name of the ui.view) is not defined in the button pressed function. I here is the code ```
class view (ui.View):
main_view = ui.View(name = 'Killer Aliens From Space!')
main_view.present(title_bar_color = 'grey')

def startup(sender):

    Scene.paused = False
    ui.View.close(main_view) # Here is where it complains


b1 = ui.Button(title = "Start")
b1.frame = (295,390,190,50)

b1.background_color = '#b03206'
b1.corner_radius = 15
b1.tint_color = 'blue'
b1.action = startup
main_view.add_subview(b1)

```
Any ideas why this is happening?

cvp

Instead of

    ui.View.close(main_view) # Here is where it complains

Use

    main_view.close() # Here is where it complains
Bjucha

@cvp thanks but now it says that ’main_view’ is not defined. When pressing the button.

cvp

@Bjucha The little script here-after works correctly but I have commented the class and the scene lines because they are not needed, except if your script is longer
Perhaps a problem of indentation if main_view is not known in startup def.

import ui

#class view (ui.View):
main_view = ui.View(name = 'Killer Aliens From Space!')
main_view.present(title_bar_color = 'grey')

def startup(sender):

    #Scene.paused = False
    main_view.close() # Here is where it complains


b1 = ui.Button(title = "Start")
b1.frame = (295,390,190,50)

b1.background_color = '#b03206'
b1.corner_radius = 15
b1.tint_color = 'blue'
b1.action = startup
main_view.add_subview(b1)
cvp

@Bjucha or use, in startup:

    sender.superview.close()
Bjucha

@cvp Thank you, that did the trick!!!