Lessons · Building apps · 26 of 36
Errors and good habits
The real error messages and their fixes; how to organise a project.
Vi checks the code as you type. Problems show as red (errors: the app can't run) or yellow (warnings: it runs, but something is off) underlines and in the Problems tab. Most have a Fix button there, or a light bulb in the editor.
| You see | It means | The fix |
|---|---|---|
Unknown container 'heder' |
a misspelt or missing name | pick the suggested name, or Create container 'heder' |
Unknown function 'ad_task' |
the function doesn't exist | pick the suggested name, or Create function 'ad_task()' |
Unknown attribute 'colour' |
not an attribute Vi knows | Change to 'color' |
Nothing to run: mark the screen with 'main'… |
no main container |
Add main container, or Mark … as the main container |
Your own files need no import… |
an import of a file of the project |
Remove this import line |
'header' is also defined in src/a.vi |
the same name in two files | rename one of them |
'name_box' is defined inside 'form' and is not visible here |
an inside name used from outside | Use 'form.name_box' |
Good habits:
- One job per file.
config.vifor settings,theme.vifor colours, a data file for the variables and the functions that change them, one file per piece of the screen incomponents/. - Colours in one place. Name them once (
violet = rgb(109, 74, 255)) and use the names. - Write a piece inside the one container that uses it; give it its own block when several do. Right-click a container for Move out and Move in.
- Name things for what they are:
task_row,score_card,add_task(). - Format Document (Shift+Alt+F) tidies spacing and puts attributes in the same order everywhere: what it is, size, look, text, layout, children, events.
Every example here runs in Vi Studio: open it in your browser (phones too) and press Start learning on the welcome page. Each code block there has a Try it button that runs it in the phone preview.
More in Building apps
- Screensgo_to, go_back, transitions, and phone / tablet / desktop.
- Containers that take valuescard(task): one container, many values.
- Repeating thingsrepeat: task in tasks, grids, index, x, y and .at().
- Reaching other containersInside names, parent.name and top-level names.
- Changing the screenA dot for one change, a block for several; wait and animate.
- Timers and gamesevery(), stop(), on_touch, place: x, y and on_hit.
- Sound and videoplay, loop, stop_sounds, audio and video.
- Files and projectssrc/, every file sees every name, one name in one file.
- The config blockApp name, store id, version, icon and splash screen.
About Vi. Vi is a free, open-source programming language for building real mobile apps. You describe each screen in plain words, and Vi compiles it to React Native (Expo) for Android, iOS and the web. Its editor, Vi Studio, runs on Windows, in any browser and on your phone, with the app running live as you type. Read more about Vi.