# Button Events Triggering unused variable 'target' error

**URL:** <http://forum.squareline.io/t/button-events-triggering-unused-variable-target-error/3837>\
**Category:** Bugs\
**Created:** [September 22, 2024, 10:43pm UTC](http://forum.squareline.io/t/button-events-triggering-unused-variable-target-error/3837 "2024-09-22T22:43:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpena2087](http://forum.squareline.io/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@gpena2087](http://forum.squareline.io/u/gpena2087)\
**Post date:** [September 22, 2024, 10:43pm UTC](http://forum.squareline.io/t/button-events-triggering-unused-variable-target-error/3837/1 "2024-09-22T22:43:38Z")

</div>

### What do you want to achieve?

Working Buttons for an ESP32S Screen, change to screen2

### What have you tried so far?

GPT says that this modification will fix the errors.  
It does however each time you export UI in SquareLine, even to adjust text position it rewrites the entire UI.C file, removing our fix making me do it each and every time I export UI.  
Fixed Code

```auto
void ui_event_Button1(lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);
    if (event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_SettingScreen, LV_SCR_LOAD_ANIM_NONE, 1, 0, &ui_SettingScreen_screen_init);
    }
}

```

Arduino IDE Error log.  
`/Users//Documents/Arduino1/Fireplacebackupspj/libraries/ui/src/ui.c: In function 'ui_event_Button1': /Users/gabe/Documents/Arduino1/Fireplacebackupspj/libraries/ui/src/ui.c:127:66: error: unused variable 'target' [-Werror=unused-variable] lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);`

**Squareline UI.C button Code:**

```auto
void ui_event_Button1( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
if ( event_code == LV_EVENT_CLICKED) {
      _ui_screen_change( &ui_SettingScreen, LV_SCR_LOAD_ANIM_NONE, 1, 0, &ui_SettingScreen_screen_init);
}

```

### Screenshot or video

### Others

- **SquareLine Studio version:**
- **Operating system:**
- **Target hardware:**

---

<div class="post-metadata">

**Author:** ![Hermit](http://forum.squareline.io/user_avatar/forum.squareline.io/hermit/32/971_2.png) [@Hermit](http://forum.squareline.io/u/Hermit)\
**Post date:** [September 23, 2024, 10:55am UTC](http://forum.squareline.io/t/button-events-triggering-unused-variable-target-error/3837/2 "2024-09-23T10:55:38Z")

</div>

Compilers generally shouldn’t give error, just warning, if there’s a declared but unused variable, as it shouldn’t cause any problems and would be optimized away by the compiler. But we know some compilers and programmers prefer this very strict approach, so we’ll check if we can disable this prepared ‘target’ variable in the export when it’s not really needed. Thanks for the feedback.

---

<div class="post-metadata">

**Author:** ![gpena2087](http://forum.squareline.io/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@gpena2087](http://forum.squareline.io/u/gpena2087)\
**Post date:** [September 23, 2024, 4:14pm UTC](http://forum.squareline.io/t/button-events-triggering-unused-variable-target-error/3837/4 "2024-09-23T16:14:40Z")

</div>

![image](http://forum.squareline.io/uploads/default/original/2X/7/765f23641a455af2cd861b6db9ab39a1de1bb6c1.png)  
Can you see any options that may be missing?  
I belive I have all required elements filled out. So I am unsure why it thinks the target is missing.

---

<div class="post-metadata">

**Author:** ![Hermit](http://forum.squareline.io/user_avatar/forum.squareline.io/hermit/32/971_2.png) [@Hermit](http://forum.squareline.io/u/Hermit)\
**Post date:** [September 23, 2024, 6:31pm UTC](http://forum.squareline.io/t/button-events-triggering-unused-variable-target-error/3837/5 "2024-09-23T18:31:22Z")

</div>

You’re not missing anything. The ‘target’ internal variable of the callback function could be used when for example you need to check the value/state of the widget, but since it’s a simple ‘CLICKED’ trigger there’s no need for that, no code is generated that uses ‘target’, but unfortunately the variable ‘target’ is still prepared by the exported code and is not liked by your compiler. What you can do now is adding the ‘-Wno-unused-variable’ or ‘-Wno-unused’ flags to your compiler settings, after ‘-Wall’ or ‘-Wextra’ flags if they’re there. That way you’ll only get a warning and your code will hopefully compile fine. In the next soon-released SquareLine Studio version the ‘target’ will be only declared and initialized where it’s necessary.
