Trying to make my first basic script with obse.

Post » Fri May 04, 2012 7:04 am

ScriptName Jail
Begin gamemode
If ( GetNumKeysPressed == 2 ) player.Gotojail
endif
end

It's to see if i can get if statements working but this doesn't work.
User avatar
Sunny Under
 
Posts: 3368
Joined: Wed Apr 11, 2007 5:31 pm

Post » Fri May 04, 2012 11:28 am

I have found that Player.GoToJail doesn't work other than in the Script Result of a Topic Conversation
Instead, try
"PrintToConsole GetNumKeysPressed %0.0f" GetNumKeysPressed
Or something like that.
User avatar
Saul C
 
Posts: 3405
Joined: Wed Oct 17, 2007 12:41 pm

Post » Thu May 03, 2012 10:45 pm

scriptname time
Begin gamemode
float time;
time = time-1
if (getkeynumpressed == 2 and time < 0 )
{
player.additem 00004330 1
time = 200
}
endif
end

this gives a time not found error and i'm not sure if my other code is correct.
User avatar
OJY
 
Posts: 3462
Joined: Wed May 30, 2007 3:11 pm

Post » Fri May 04, 2012 10:57 am

declare your variables before the Begin block and the syntax of your code will not be compile in the CS
try this
scriptname timefloat timebegin gamemode	set time to time - 1	if getkeynumpressed == 2 && time < 0		player.additem 00004330 1		set time to 200	endifend
There's a lot of Scripting tutorials here: http://cs.elderscrolls.com/index.php/Portal:Scripting
User avatar
Jennifer May
 
Posts: 3376
Joined: Thu Aug 16, 2007 3:51 pm

Post » Thu May 03, 2012 10:24 pm

You can use the editorID name instead of the formID code, it is actually better that way since your scripts will gain clarity.
Also, OBSE has its own commands for variable assignment, which will debug info to the console if something goes wrong. Instead of 'set ... to ...', get used to 'let ... := ...', and you won't ever want to go back (I swear!).
And you can even use mathematical signs instead of the : , so you can simplify things like
set time to time - 1
to
let time -= 1
User avatar
GLOW...
 
Posts: 3472
Joined: Thu Aug 03, 2006 10:40 am

Post » Fri May 04, 2012 6:35 am

Agreed with migck.
But I didn't know you could do -= with Let.
I assume you can do +=, --, and ++, as well.
User avatar
Michelle Serenity Boss
 
Posts: 3341
Joined: Tue Oct 17, 2006 10:49 am

Post » Thu May 03, 2012 11:43 pm

http://obse.silverlock.org/obse_command_doc.html#OBSE_Expressions
User avatar
Causon-Chambers
 
Posts: 3503
Joined: Sun Oct 15, 2006 11:47 pm

Post » Fri May 04, 2012 11:57 am

I want to be able to make 5 daedaric arrows after 200 frames when pressing Q but it doesn't work. The editor thinks it's fine though.

scriptname time
float time
begin gamemode
let time -= 1
if getkeypress 16 && time < 0
player.additem 0001EFD3 5
set time to 200
endif
end
User avatar
lacy lake
 
Posts: 3450
Joined: Sun Dec 31, 2006 12:13 am

Post » Fri May 04, 2012 1:36 am

I want to be able to make 5 daedaric arrows after 200 frames when pressing Q but it doesn't work. The editor thinks it's fine though.

scriptname time
float time
begin gamemode
let time -= 1
if getkeypress 16 && time < 0
player.additem 0001EFD3 5
set time to 200
endif
end

If you want to have this executed after exactly 200 frames, you're assuming that your script will run every single frame.
This is only true for object type scripts, which are attached to a base object. As long as a reference of this object is loaded ingame (i.e. it is "physically" present in a loaded cell), the script will be run for every frame as expected.
Once you leave the cell, execution will be suspended, unless you haven't unchecked the "No low-level processing" flag for that specific reference.

Be aware that such "run-every-frame" code can put heavy load on your CPU and therefore is not a good practice (unless explicitely needed).

In contrary, quest type scripts (attached to a quest) will run in a 5 seconds interval by default (which can be changed by setting a value for fQuestDelayTime). This is much more recommended. As the 5 sec might cause problems with keyPressed detection, you should consider placing your code in a quest script anyway, but changing fQuestDelayTime to a lower value, such as 0.2 or 0.1.

Example:
ScriptName MyQuestScriptfloat fQuestDelayTimeshort doOnceshort questEndedbegin gameMode  if doOnce == 0	set fQuestDelayTime to 0.2	set doOnce to 1  endif  [... your key detection code goes here ...]end

As a good practise, once your "run-very-often" logic isn't needed anymore (e.g. if the parent quest is completed), try to change fQuestDelayTime back to normal (i.e. a value of 5 or higher).
User avatar
Annick Charron
 
Posts: 3367
Joined: Fri Dec 29, 2006 3:03 pm


Return to IV - Oblivion