FANDOM


This page will be a bit of a departure from my introductory tutorial series. Here I will present some general coding strategies for more advanced users. If you're looking for ways to work faster, or write better/more powerful code, give this a look and leave your comments below!

This tutorial covers advanced topics for improving your code and accomplishing more within Petit. Power users may already be familiar with many of these strategies.

Editing strategiesEdit

  • Memorize your @Label names and use the search tool to navigate through your code more quickly
  • Holding L and pressing Y will delete an entire line of code at once, much faster than deleting the line by holding Y
  • Use comments, line-breaks, and indentation to sculpt your code so you can recognize features faster when scrolling
  • If you always change editor properties like the text on the function keys or the tabstep, paste the code that makes those changes into the top of the application you are working on and run it as soon as you launch Petit so your settings are ready. Alternately, you can make a setup program and run that

Code architecture strategiesEdit

  • Store values that never change but get used a lot to variables:

STARTX = 25
SPOFS 0,STARTX,20
SPOFS 1,STARTX,50
SPOFS 2,STARTX,70

This makes it easier to change them later
  • You can store @label names in variables and use those variables with GOTO and GOSUB. This is one of the most powerful features in Petit, because it allows you to do things like this:

DIM BTNFUNCS$(5)
BTNFUNCS$(0) = "@USEPOTION"
SPSETV 5,0,0
...
@USRTOUCHEDBTN
FUNC$ = BTNFUNCS$(SPGETV SPR,0)
GOSUB FUNC$

e.g. you can essentially attach labels to sprites and go to those labels when something happens to the sprite
  • Store indexes into named variables so you don't have to remember the indexes and your code is more readable

DIM EMPLOYEE$(5,3)
NAME = 0
JOB = 1
DEPARTMENT = 2
...
EMPLOYEE$(1,NAME) = "FRED"
EMPLOYEE$(1, JOB) = "DRIVER"
EMPLOYEE$(1, DEPARTMENT) = "SHIPPING"

  • Use goto as an alternative to putting multiple instructions on one IF line:

IF (LOWHEALTH == FALSE) THEN GOTO @SKIP
COLOR RED
PRINT "YOUR HEALTH IS VERY LOW"
BEEP 5
@SKIP


Performance strategiesEdit

  • Accessing a value in an array is much slower than accessing a value in a variable. If you're going to be using a value from an array more than three times, copy it to a variable and use that (otherwise the overhead of copying to the variable outweighs the benefits of the variable being faster)

This page will likely be expanded and reformatted over time

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.