+ Reply to Thread
Results 1 to 4 of 4

Thread: Constant or Populate on init

  1. #1
    Wire Noob Magic21 is on a distinguished road Magic21's Avatar
    Join Date
    Feb 2010
    Posts
    24

    Default Constant or Populate on init

    Question 1:
    How do I assign Pitch to the value of "100" only once, perhaps upon the creation of the chip?

    Code:
    @name PortalSong
    @inputs PitchUp PitchDown On Off
    @outputs Pitch
    @persist
    
    Pitch=100
    if(On){soundPlay(1,0,"music/portal_still_alive.mp3")}
    if(Off){soundStop(1)}
    if(PitchUp){Pitch++,soundPitch(1,Pitch)}
    if(PitchDown){Pitch--,soundPitch(1,Pitch)}
    
    The way the code stands right now, pitch is always 100 because when the chip executes it always writes Pitch=100. So when any button is pressed it'll rewrite Pitch to 100.


    Question 2:
    How do I assign fire only once values?

    Scenario: Chair&Adv Pod Controller. I want print("fire only once") to fire when Activate == 1 (when someone sits in the chair)

    Faulty Example:
    Code:
    @name ChairThing
    @inputs Mouse1 Active
    @outputs
    @persist
    
    if(Active){print("Welcome to the chair!")}
    if(Mouse1){print("You hit Mouse1")}
    
    This code will fire "Welcome to the chair!" when you enter the vehicle and also whenever you press Mouse1 (because the chip fires when either input occurs).

  2. #2
    Wire Sofaking Tolyzor is on a distinguished road Tolyzor's Avatar
    Join Date
    Aug 2008
    Location
    UK
    Posts
    409

    Default Re: Constant or Populate on init

    Code:
    @name PortalSong
    @inputs PitchUp PitchDown On Off
    @outputs Pitch
    @persist
    
    if (first()) {Pitch=100}
    if(On){soundPlay(1,0,"music/portal_still_alive.mp3")}
    if(Off){soundStop(1)}
    if(PitchUp){Pitch++,soundPitch(1,Pitch)}
    if(PitchDown){Pitch--,soundPitch(1,Pitch)}
    
    Code:
    @name ChairThing
    @inputs Mouse1 Active
    @outputs
    @persist
    
    if(Active & ~Active){print("Welcome to the chair!")}
    if(Mouse1 & ~Mouse1){print("You hit Mouse1")}
    

  3. #3
    Wire Amateur cheezychicken is on a distinguished road cheezychicken's Avatar
    Join Date
    Feb 2009
    Location
    at a computer...
    Posts
    80

    Smile Re: Constant or Populate on init

    Quote Originally Posted by Magic21 View Post
    Question 1:
    How do I assign Pitch to the value of "100" only once, perhaps upon the creation of the chip?

    Code:
    @name PortalSong
    @inputs PitchUp PitchDown On Off
    @outputs Pitch
    @persist
    
    Pitch=100
    if(On){soundPlay(1,0,"music/portal_still_alive.mp3")}
    if(Off){soundStop(1)}
    if(PitchUp){Pitch++,soundPitch(1,Pitch)}
    if(PitchDown){Pitch--,soundPitch(1,Pitch)}
    
    to assign a variable when the chip is spawned use:
    Code:
    if (first()|duped()) {do stuff}
    
    Quote Originally Posted by Magic21 View Post

    Question 2:
    How do I assign fire only once values?

    Scenario: Chair&Adv Pod Controller. I want print("fire only once") to fire when Activate == 1 (when someone sits in the chair)

    Faulty Example:
    Code:
    @name ChairThing
    @inputs Mouse1 Active
    @outputs
    @persist
    
    if(Active){print("Welcome to the chair!")}
    if(Mouse1){print("You hit Mouse1")}
    
    .
    hrm... maybe a
    Code:
    if (Active&~Active) {do stuff}
    
    not too sure about that last one but its something to do with ~
    hope i helped


    Quote Originally Posted by Lol-Nade View Post
    OR maybe the igniter can be used to pull guns out of your ass, as well as ignite props?

  4. #4
    Wire Noob Magic21 is on a distinguished road Magic21's Avatar
    Join Date
    Feb 2010
    Posts
    24

    Default Re: Constant or Populate on init

    sweet, thanks! Going to test it now.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts