Jump to content

IsKeyPressed Errors


Archey6

Recommended Posts

I'm trying to compile this code

 

Scriptname GimmeGold Extends Input
{Free Gold Sir}

Function GiveMeGold()
if IsKeyPressed(86) == 1
	Game.GetPlayer().AddItem(Gold, 2, true)
endif
endFunction

 

but I'm getting these errors

 

Starting 1 compile threads for 1 files...
Starting 1 compile threads for 1 files...
Compiling "GimmeGold"...
c:\games\steam\steamapps\common\skyrim\Data\Scripts\Source\GimmeGold.psc(5,4): global function IsKeyPressed cannot be called on an object
c:\games\steam\steamapps\common\skyrim\Data\Scripts\Source\GimmeGold.psc(5,21): cannot compare a none to a int (cast missing or types unrelated)
c:\games\steam\steamapps\common\skyrim\Data\Scripts\Source\GimmeGold.psc(6,27): variable Gold is undefined
No output generated for GimmeGold, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on GimmeGold

Edited by archeyreece
Link to comment
Share on other sites


  1.  
  2. Your script shouldn't extend Input, have it extend something else.
  3. Import Input.
  4. Create a property for gold.

 

Alright, I decided I wouldnt add an item, but just show a debug message. this is my current code, it compiles but it doesn't do anything in-game.

 

Scriptname MessageMe
{Playing around}

Import Input

function MsgMe()
if IsKeyPressed(0x57) == 1
	Debug.MessageBox("Success!")
endIf
endFunction

Link to comment
Share on other sites

You realize that it would only work if you happen to be pressing the F11 key when you call the MsgMe() function right? Do you know how to call functions?

 

I didn't realize that. I've tried the code without a function, but I get an error. I've tried calling the function by using

 

MsgMe()

 

But that too just gives an error.

Edited by archeyreece
Link to comment
Share on other sites

All code needs to be contained within functions or events. This is a working example of using IsKeyPressed:

 

Scriptname Example extends Quest

import Input

Event OnInit()
RegisterForSingleUpdate(0.1)
EndEvent

Event OnUpdate()
if (IsKeyPressed(0x57))
	Debug.MessageBox("You stopped the quest.")
	Stop()
else
	RegisterForSingleUpdate(0.1)
endif
EndEvent

Edited by fg109
Link to comment
Share on other sites

All code needs to be contained within functions or events. This is a working example of using IsKeyPressed:

 

Scriptname Example extends Quest

import Input

Event OnInit()
RegisterForSingleUpdate(0.1)
EndEvent

Event OnUpdate()
if (IsKeyPressed(0x57))
	Debug.MessageBox("You stopped the quest.")
	Stop()
else
	RegisterForSingleUpdate(0.1)
endif
EndEvent

 

 

Not sure whats wrong but even that won't work.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...