Author Topic: Scripting Basics  (Read 6596 times)

0 Members and 1 Guest are viewing this topic.

Offline Itchigo

  • Victory is mine!!
  • Administrator
  • Pinball Wizard
  • *****
  • Posts: 1,423
  • Country: us
  • Karma: +10/-0
Scripting Basics
« on: November 07, 2012, 06:40:23 AM »
Scripting a table- The main areas to cover:

Table -Init: This is what happens when the table is first rendered (i.e. comes on your screen)

Keydown: This is what happens when you press a key down.

Keyup: This is what happens when you let that key up.

Newgame/Startgame: What to do when the start button is pressed. The Keyup/Down Sub makes it come here.

Tilt: Essentially what I do is this, when you "shake" the game it adds to a count. Tiltcount=Tiltcount+1. When Tiltcount reaches 3 you have tilted. Disable the objects, and reset the lights via the script. Tilt then =True. You always want If Tilt=False in your object code because you don't want to add score during tilt, do you? Same with flippers, and bumpers. If the Tilt timer runs out then the Tiltcount resets to 0. The timer starts after the first time you shake the game.

Nextball/Drain: What to do when going to the next ball/player. My system is very easy, it's based on balls/players (obviously). Example, with 4 players. Your on ball 1 and lose the ball. Player=PLayer+1 makes it go to Player2. Say Player4 loses a ball, Player=Player+1 makes it go to Player5. Well there is no player5. So, If Player is greater then > Players Then Ball=Ball +1. So if player exceeds the number of players- go to the next ball and Player=1 (1st Player). I use the same idea with Ball/Balls. Ball is the Ball number, and Balls is the number of balls pergame. This concept was inspired by Bob5453, I just expanded it a bit.

Extraball (Sub Addball): Easy with the above system in place. Player already= player +1 when you lose the ball, so what I do is, If Extraball light is on Then Player=Player-1. It reverses ther effect of losing the ball and it only happens with the Extraball light on, so when it resets, everything is back to normal.

Bonus: This is optional. I use my friends routine he wrote for me, and just tweak it a bit. It's a bit complicted to explain, I'll just explain what happens before and after. The ball hits the drain, The bonus routine starts, then finishes. It goes to Bonusended or Ballended to go to the next ball. In the case of collecting bonus WITHOUT losing the ball, I start the bonus timer and use a true/False to either kick the ball out and bypass Nextball, or go to Nextball. If Tilt=True (you've tilted) then Exit sub, (bypass the bonus sub entirely).

Scoring: Scoring is already done on my template, but on a scratch built table, you have to tell it what score is. Score=Score +Points. Your score is just a value, what added to it is points. Scoreplayer1 is player 1's score. Addscore adds points to this value.

Gameover: This is what to do when the game is over, Match, etc.

These are the basic areas of most pins.



Next we'll cover some very basic scripts.

Everything done is inside of a Subroutine, or Sub. Examples:

Sub Bumper1_Hit()            '(Bumper script example)
    Playsound "play this sound in quotes"
    Addscore 100             '(You need a number here).
End Sub

Bumper1 has been hit by a ball, play the sound and add 100 points.
If you're going to make any comments in your script, you need to use this ' . The apostrophy will make the computer ignore everything else on that line after it. It will also turn the code after it green, letting you know it will be ignored.

If/Then statements:

Sub Bumper1_Hit()            '(Bumper script example)
If  Tilt=False Then
    Playsound "play this sound in quotes"
    Addscore 100
End If            
End Sub

If Tilt=False Then it will play the sound and add the score. If you have tilted this will be ignored. Everything between the If/Then is one event, so if the If statement conditions are met, everything will happen in between. You need an "End If" to complete the sub if you use an if. Generally the Ifs/End ifs must match but there are some exceptions.

Sub Example()
If  Light1.State=1 Then Light1a.State=1
End If
If  Light2.State=1 Then Light2a.State=1
End If
If  Light3.State=1 Then Light3a.State=1
End If
If  Light4.State=1 Then Light4a.State=1
End If
End Sub

Sub Bumper1_Hit()            '(Bumper script example)
Light.State=1
If  Tilt=False Then
    Playsound "play this sound in quotes"
    Addscore 100
End If            
End Sub

Now Light 1 will turn on no matter what when Bumper1 is hit, but the other things will only happen when Tilt=False.

Sub Bumper1_Hit()            '(Bumper script example)
If  Tilt=False Then
    Playsound "play this sound in quotes"
    Addscore 100
End If  
Else Light1.State=1          
End Sub

If the conditions are not met the "Else" takes over when Bumper1 is hit.

Here are some very examples of object scripts.

Bumper:

Sub Bumper1_Hit()            
If  Tilt=False Then
    Playsound "play this sound in quotes"
    Addscore 100
End If            
End Sub

Triggers:

Sub Trigger1_Hit()            
If  Tilt=False Then
    Playsound "play this sound in quotes"
    Addscore 100
End If            
End Sub

Kickers:

Sub Kicker1_Hit()                  

If  Tilt= False Then                
     
    Addscore 500              
       
    PlaySound "Ding1"              
    Kicker1.Kick 355,35  
             'Kicking the ball out to angle 355 degrees, strength 35.
End If
 
End Sub

Kicker using a timer:

Sub Kicker1_Hit()                  
If  Tilt= False Then              

    Addscore 500                  
   
    PlaySound "Ding1"              
    Kicker1Timer.Enabled=True   'This means turn on the timer.
End If
 
End Sub
 
 

Sub Kicker1Timer_Timer()            
   
    Kicker1.kick 355,35            
   
    Playsound "Saucer"            
    Kicker1Timer.Enabled=False
  'This means turn off the timer.
End Sub

Note! If you do not turn off the timer, it will just do the same thing over and over in the timer sub. That's why you need Timer.Enabled=False. Your best bet is to uncheck enabled, use the options to set the interval, then use the script to set the enabling. You can enable it (or turn it on) whenever and wherever, and as many times as you like. The timer interval is either set on the object itself (through Options), or in the script. Timer.Interval=1000  (1000= 1 second by the way). You can also change the timer interval. Timer.Interval=Timer.Interval-2  This shortens the timer by 2 units. This is useful for a game like Quicksilver, and you want to speed up the Bonus Routine.

Drop Targets:

Sub Target1_Hit()
Target1.Isdropped =True    'The targets is down.
End Sub

Target1.IsDropped=False    'The target is back up.

Target Script (2 Targets):

Sub Target1_Hit()                      
If  Tilt= False Then                
   
    PlaySound""                    
     
    AddScore 1000                  
     
    Target1.IsDropped=True            
     
CheckTargets                
End If
 
End Sub

Sub Target2_Hit()                      
If  Tilt= False Then                
   
    PlaySound""                    
     
    AddScore 1000                  
     
    Target2.IsDropped=True            
     
CheckTargets                
End If
 
End Sub

Sub CheckTargets()
If  Target1.Isdropped=True And Target2.IsDropped=True Then
    Addscore 1000
    Playsound "TargetReset"
    Target1.Isdropped=False
    Target2.IsDropped=False
End If
End Sub

The target is hit, it checks to see if they're both dropped. If they are then it  adds 1000, plays the reset sound, and resets them. You can also use timers here to do this. Example:

Sub Target1_Hit()                      
If  Tilt= False Then                
   
    PlaySound""                    
     
    AddScore 1000                  
     
    Target1.IsDropped=True            
     
CheckTargets                
End If
 
End Sub

Sub Target2_Hit()                      
If  Tilt= False Then                
   
    PlaySound""                    
     
    AddScore 1000                  
     
    Target2.IsDropped=True            
     
CheckTargets                
End If
 
End Sub

Sub CheckTargets()
If  Target1.Isdropped=True And Target2.IsDropped=True Then
    Timer1.Enabled=True
End If
End Sub

Sub Timer1_Timer()
    Timer1.Enabled=False
    Addscore 1000
    Playsound "TargetReset"
    Target1.Isdropped=False
    Target2.IsDropped=False
End Sub

This is a basic overview of how to use various things for your script. I know it can seem daunting at first, but consider this. I barely knew windows when I was learning this, so if I can do it, so can you.

Anyone want to add to this?
Tremble in fear! Behold my Bankai!


Offline faralos

  • Full Member
  • ***
  • Posts: 235
  • Karma: +1/-0
RE: Scripting Basics
« Reply #1 on: November 07, 2012, 06:48:54 AM »
quick question, I have a song that is about 7 minutes in length
I want two lights to flash at its end does that mean I must break down 7 minutes into seconds
 then time the lights to flash at its end? that's a hell of a lot of seconds to add into a light array
just for them to flash once!
how many zeros can we add to the blink interval? IS there any limit?

woopsies one more question... I am working with Anthias' table template
 in this one he has ramp bonuses set up for scoring values
 how must I write them in? is it just
'rampbonus+1' or is there more to it? I am getting all sorts of odd errors
 when trying to write addscore for this wip of mine (dogtown uses Anthias' template)
and that problem is mostly what is holding up that wip
I am never wrong Once I thought I was
 but I was merely mistaken

Offline Itchigo

  • Victory is mine!!
  • Administrator
  • Pinball Wizard
  • *****
  • Posts: 1,423
  • Country: us
  • Karma: +10/-0
RE: Scripting Basics
« Reply #2 on: November 07, 2012, 07:12:08 AM »
Quote from: 'faralos' pid='291' dateline='1352292534'

quick question, I have a song that is about 7 minutes in length
I want two lights to flash at its end does that mean I must break down 7 minutes into seconds
 then time the lights to flash at its end? that's a hell of a lot of seconds to add into a light array
just for them to flash once!

You could use a timer, but I really don't mess with putting any more than clips into my tables.


how many zeros can we add to the blink interval? IS there any limit?



No idea. I'm only now starting to use this.


woopsies one more question... I am working with Anthias' table template
 in this one he has ramp bonuses set up for scoring values
 how must I write them in? is it just
'rampbonus+1' or is there more to it? I am getting all sorts of odd errors
 when trying to write addscore for this wip of mine (dogtown uses Anthias' template)
and that problem is mostly what is holding up that wip


I'd have to see it, but I'd use  a trigger on the ramp for bonuses. You can also make a very small light (radius 1), then use that light for an If/Then.
trigger1_Hit- addscore 1000
If light1.state=1 then addscore 10000
A radius of 1 is so small it wont be seen and it's useful for scripting possibilities.
Tremble in fear! Behold my Bankai!


Offline faralos

  • Full Member
  • ***
  • Posts: 235
  • Karma: +1/-0
RE: Scripting Basics
« Reply #3 on: November 07, 2012, 08:37:32 AM »
I have  triggers what I am trying to do is add his bonus scoring
 he set it up as
the regular addscore (whatever value here)
ramp bonus
 lane bonus
 all these add to the main score as added bonuses if hit
later today (I have a  ten thirty interview at McCallion staffing for work)
I'll upload it to speedyshare for you to download and look at
or if it's relatively short I'll post the coding lines here for your perusal
I am never wrong Once I thought I was
 but I was merely mistaken