Quantcast

Jump to content

» «
Photo

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

8 replies to this topic
PlayPrey
  • PlayPrey

    string ScriptSkillLevel = "Low-Med";

  • Members
  • Joined: 02 Jul 2012
  • Norway

#1

Posted 15 February 2014 - 07:09 PM Edited by PlayPrey, 15 February 2014 - 08:58 PM.

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 GTA
Imports System.Drawing
Imports System.Windows.Forms
Public 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 Sub
End 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


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#2

Posted 15 February 2014 - 07:45 PM Edited by InfamousSabre, 15 February 2014 - 07:48 PM.

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)


PlayPrey
  • PlayPrey

    string ScriptSkillLevel = "Low-Med";

  • Members
  • Joined: 02 Jul 2012
  • Norway

#3

Posted 15 February 2014 - 08:59 PM

Sorry, updated!


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#4

Posted 15 February 2014 - 09:28 PM Edited by LordOfTheBongs, 15 February 2014 - 09:32 PM.

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


PlayPrey
  • PlayPrey

    string ScriptSkillLevel = "Low-Med";

  • Members
  • Joined: 02 Jul 2012
  • Norway

#5

Posted 15 February 2014 - 09:42 PM

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? :)


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#6

Posted 15 February 2014 - 09:56 PM

 

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


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#7

Posted 15 February 2014 - 11:16 PM Edited by InfamousSabre, 15 February 2014 - 11:18 PM.

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.

  • LordOfTheBongs likes this

Michael Wojtanis
  • Michael Wojtanis

    Rinepim

  • Members
  • Joined: 17 Jul 2013

#8

Posted 16 February 2014 - 04:06 PM

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... ;)


PlayPrey
  • PlayPrey

    string ScriptSkillLevel = "Low-Med";

  • Members
  • Joined: 02 Jul 2012
  • Norway

#9

Posted 16 February 2014 - 05:47 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users