Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (84,963 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

Sign in to follow this  
PlayPrey

[VB] Timers crash on tick, object reference not set as object

Recommended Posts

PlayPrey

Hi, first post here in the forums :D

 

Ive decided to start some minor gta 4 modding.

 

In my script i need to use timers, and every time i have tried to use it- i get the following error:

2014-02-15 20:05:51 - STARTING SCRIPTS...2014-02-15 20:05:51 -  ...successfully started script 'Tutorial.Main'!2014-02-15 20:05:51 -  ...successfully started script 'Tutorial.Commands'!2014-02-15 20:05:51 -  ...successfully started script 'Tutorial.AI'!2014-02-15 20:05:52 - Error during Tick in script 'Tutorial.AI':                      System.NullReferenceException: Object reference not set to an instance of an object.                         at Tutorial.AI.suvStalkerStalk(Object sender, EventArgs e)                         at GTA.Script.TryTick()                         at GTA.Script.DoTick()                         at GTA.ScriptThread.OnTick()

Yes, i used a template from a tutorial to get started, i havent renamed it yet.

 

If im missing essential information, please tell me, Ill update this if needed...

 

If i find out the solution, i will update this with the solution :)

 

 

EDIT :D

 

 

InfamousSabre reminded me kindly that i needed to show my own code, which i for some reason forgot... Sorry!

 


Imports GTAImports System.DrawingImports System.Windows.FormsPublic Class AI    Inherits Script    Public S_SUV As Vehicle    Public S_SEDAN As Vehicle    Public S_BIKE As Vehicle    Public SUV_DRIVER As Ped    Private Sub suvStalkers(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown        If e.Key = Keys.L AndAlso Keys.O Then            S_SUV = World.CreateVehicle("LANDSTALKER", Player.Character.Position.Around(10.0F))            If S_SUV.Exists = True Then                SUV_DRIVER = World.CreatePed("M_Y_HARLEM_01", Player.Character.Position.Around(10.0F))            End If            If S_SUV.Exists = True And SUV_DRIVER.Exists = True Then                SUV_DRIVER.WarpIntoVehicle(S_SUV, VehicleSeat.Driver)            End If            If SUV_DRIVER.isInVehicle Then            End If        End If    End Sub    Public Sub New()        Me.Interval = 5000 ' Interval is the time between two Ticks (in milliseconds)    End Sub    Private Sub suvStalkerStalk(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick        If S_SUV.Exists = True Then            SUV_DRIVER.CurrentVehicle.SoundHorn(1000)        End If    End SubEnd Class

AND for some reason after i added the " If S_SUV.Exists = True Then

 

it worked? Does a timer need stuff to be inside IF stuff or something to work proberly? :p

Edited by PlayPrey

Share this post


Link to post
Share on other sites
InfamousSabre

We can even begin to help you unless you show us your code. The error is right, as it always will be.

Basically you're doing something similar to:

 

Question: Who should I release from prison?

Answer: Inmate.

Response: System.NullReferenceException: Object reference not set to an instance of an object.

 

There are many Inmates in a prison, therefore the answer was incorrect and caused an error.

You must give it an instance of an Inmate. Inmate #B33920 would have been an acceptable answer, because it is an instance of an Inmate.

 

 

 

 

 

(For the record, this was just an example. I don't have any opinion on whether Inmate #B33920 should be released or not)

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
PlayPrey

Sorry, updated!

Share this post


Link to post
Share on other sites
LordOfTheBongs

well gtaforums code formatting sucks as it commented out half your script...

 

but in your tick u just check if vehicle exists and if true u do something with the driver... so i guess vehicle existed and driver didnt...

 

also i recommend c#... that is some ugly sh*t lol

 

change to...

 

 

If SUV_DRIVER.Exists = True And SUV_DRIVER.CurrentVehicle.Exists = True Then    SUV_DRIVER.CurrentVehicle.SoundHorn(1000)End If

 

now i have to take a shower from using that god awful language

 

and dont use .Exists because it will crash if the object is null... use Game.Exists, it will check null first then check if it exists

Edited by LordOfTheBongs

Share this post


Link to post
Share on other sites
PlayPrey

well gtaforums code formatting sucks as it commented out half your script...

 

but in your tick u just check if vehicle exists and if true u do something with the driver... so i guess vehicle existed and driver didnt...

 

also i recommend c#... that is some ugly sh*t lol

 

change to...

If SUV_DRIVER.Exists = True And SUV_DRIVER.CurrentVehicle.Exists = True Then    SUV_DRIVER.CurrentVehicle.SoundHorn(1000)End If

now i have to take a shower from using that god awful language

 

and dont use .Exists because it will crash if the object is null... use Game.Exists, it will check null first then check if it exists

I want to switch to C# but i can't find any tutorials for it for GTA 4 scripting, do you know of any? :)

Share this post


Link to post
Share on other sites
LordOfTheBongs

 

well gtaforums code formatting sucks as it commented out half your script...

 

but in your tick u just check if vehicle exists and if true u do something with the driver... so i guess vehicle existed and driver didnt...

 

also i recommend c#... that is some ugly sh*t lol

 

change to...

If SUV_DRIVER.Exists = True And SUV_DRIVER.CurrentVehicle.Exists = True Then    SUV_DRIVER.CurrentVehicle.SoundHorn(1000)End If

now i have to take a shower from using that god awful language

 

and dont use .Exists because it will crash if the object is null... use Game.Exists, it will check null first then check if it exists

I want to switch to C# but i can't find any tutorials for it for GTA 4 scripting, do you know of any? :)

 

well because of gta i learned programming. I didnt really use a tutorial but lots of trial and error and asking questions in irc and stuff. Lots of googling. I think more important is u learn c# itself and at the same time trying to come up with ideas for gta and trying to write them. There is no tutorial that will tell u how to script gta. The tutorial that guy uploaded is nice to get an introduction but you can only learn by learning the language and how to program. Then figuring out gta bugs and stuff is easier, it is never easy though lol

Share this post


Link to post
Share on other sites
InfamousSabre

well because of gta i learned programming. I didnt really use a tutorial but lots of trial and error and asking questions in irc and stuff. Lots of googling. I think more important is u learn c# itself and at the same time trying to come up with ideas for gta and trying to write them. There is no tutorial that will tell u how to script gta. The tutorial that guy uploaded is nice to get an introduction but you can only learn by learning the language and how to program. Then figuring out gta bugs and stuff is easier, it is never easy though lol

 

 

Same here. I wanted to learn C# so I could start writing my games in a more "accepted" programming language. GTA4 scripting was just an incentive to learn.

I learned by tearing apart other scripts and seeing how they worked. modifying them do do different things. then started writing my own. The guys in the IRC are a big help too.

When lost, I'll consult stackoverflow.com or google.com for c# questions, and gtamodding.com, shdn documentation, and Native list for gta specific questions.

When REALLY lost I'll post here or ask in IRC, but only if I've spent hours trying to figure something out and just cant get it.

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Michael Wojtanis

I remeber my first scripts in notepad -.-

 

Not i use Visual Studio C# 2010 [free]. Good thing, because before i run game and watch where is problem from console... ;)

Share this post


Link to post
Share on other sites
PlayPrey

I remeber my first scripts in notepad -.-

 

Not i use Visual Studio C# 2010 [free]. Good thing, because before i run game and watch where is problem from console... ;)

I have never used notepad for coding :) I use Visual Studio Express 2013 :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.