Defining variables within mode blocks?

Post » Thu Jan 21, 2010 1:26 pm

So like I keep coming upon script like this.


scn CrNightkinCloakUntilFireScriptshort combatcheckshort soundcheckfloat timerEffectint Cloaked								; 0 = Stealth Boy effect not on											; 1 = Stealth Boy effect on											; This var is meant to ensure we never try to remove											; the effect when it's not already on.begin onLoad	ModActorValue sneak 100	; Add the effect, update the flag	if Cloaked == 0		addspell StealthBoyInvisibilitySpell		set Cloaked to 1	endif	set soundcheck to 0	set timerEffect to 0endbegin OnSTARTCombat	set combatcheck to 1endbegin OnCombatEND	set combatcheck to 0endbegin OnDeath	set combatcheck to 0	; If the nightkin is currently using the Stealth Boy effect, remove it	if Cloaked == 1		RemoveSpell StealthBoyInvisibilitySpell		set Cloaked to 0	endifendbegin GameMode	ref refvar             ;   <--------------- YO ITS RIGHT IN THE BLOCK	set refvar to this		;if GetDetected player	;	startcombat player	;endif	if combatcheck == 1		ref mytarget       ;   <---------------------- YO IT DID IT AGAIN		set mytarget to refvar.GetCombatTarget		endif	else		if refvar.GetDead == 0;			addspell StealthBoyInvisibilitySpell					set soundcheck to 0		endif	endif	if GetAnimAction == 2 && Cloaked == 1;		ShowWarning "Nightkin attacking, decloaking now"		RemoveSpell StealthBoyInvisibilitySpell		set Cloaked to 0	endifend



And this isn't the only place I've seen this.

Alright so. huh??? I didn't even know you could do that?
User avatar
Fanny Rouyé
 
Posts: 3316
Joined: Sun Mar 25, 2007 9:47 am

Post » Thu Jan 21, 2010 10:55 am

According to the http://geck.gamesas.com/index.php/Declaring_Variables:
A local variable can be placed anywhere within the script code, it only needs to be declared before the first command that uses it. Usually you declare all variables on top of the script, though, to improve the script's readability.


So, yeah... you can do it, but it's just like indenting IF blocks, it just makes maintaining the script easier if you declare all the variables at the top of the script.
User avatar
Catherine Harte
 
Posts: 3379
Joined: Sat Aug 26, 2006 12:58 pm

Post » Thu Jan 21, 2010 11:20 am

:D

!!!!!!!!!!!!!!!!!

* begins a new era of unreadable, cryptic, yet functional code *

hehehehh
User avatar
Aaron Clark
 
Posts: 3439
Joined: Fri Oct 26, 2007 2:23 pm

Post » Thu Jan 21, 2010 8:28 pm

:D

!!!!!!!!!!!!!!!!!

* begins a new era of unreadable, cryptic, yet functional code *

hehehehh

I think I'll follow you on that. People already complain about my scripts being almost indecipherable, so I'll really give them something to scratch the head over. :evil:

That might really be fun, seeing how disorienting we can make the scripts...
User avatar
Sarah Kim
 
Posts: 3407
Joined: Tue Aug 29, 2006 2:24 pm

Post » Thu Jan 21, 2010 7:02 pm

:D

!!!!!!!!!!!!!!!!!

* begins a new era of unreadable, cryptic, yet functional code *

hehehehh

lol... :slap:
There is nothing new about cryptic scripts around here, but I do have some tips for ya,
don't use comments
no blank lines
no indents
don't use descriptive variable names
don't use capitalization....

Oh, and when you post your script because it is impossible to debug, don't use CODE tags, or SPOILER tags.... so that it will end up looking something like this:

scn sssgunnysackcontscript
int actstate
int button
float gsw
begin onactivate
if isactionref player == 1
if sssgunnysackcontstasisref.actstate == 1
set gsw to sssgunnysackcontstasisref.fgsiw
set sssgunnysackcontstasisref.actstate to 2
endif
showmessage sssgunnysackcontmessage
set actstate to 1
endif
end
begin gamemode
if actstate != 0
if actstate == 1
set button to getbuttonpressed
if button > -1
if button == 0
float iw1
set iw1 to player.getav inventoryweight
activate player 0
set actstate to 2
return
elseif button == 1
if gsw != sssgunnysackcontstasisref.fgsiw
set sssgunnysackcontstasisref.fgsiw to gsw
set gsw to (gsw + 0.1)
setweight gsw sssgunnysackmisc
endif
removeallitems sssgunnysackcontstasisref, 1
player.additem sssgunnysackmisc 1 1
set sssgunnysackcontstasisref.actstate to 0
set actstate to 0
disable
markfordelete
endif
endif
endif
if actstate == 2
float iw2
set iw2 to player.getav inventoryweight
if iw1 != iw2
set iw1 to (iw1 - iw2)
set gsw to (gsw + iw1)
endif
set actstate to 0
endif
endif
end

...pretty, ain't it? :dance:
User avatar
Dalia
 
Posts: 3488
Joined: Mon Oct 23, 2006 12:29 pm

Post » Thu Jan 21, 2010 12:44 pm

lol... :slap:
There is nothing new about cryptic scripts around here, but I do have some tips for ya,
don't use comments
no blank lines
no indents
don't use descriptive variable names
don't use capitalization....


Well thing is - - - its possible for code to be cryptic and nuts. yet be indented perfectly, and commented, and capitalized, and ...

Yeah see that's where it's at! "doesn't this code look nice" "well yeah but ... " hehe

I don't have FO3's geck open ATM but, the FOOK follower weapon selection code is kinda like... that.
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Thu Jan 21, 2010 3:39 pm

If you really want to make your scripts hard to follow, use misleading variable names. Mixing up common variable names like "doOnce", "count" or "target" can make a script take ages to follow. If you're really dedicated/evil, then you can use FNVEdit to remove the source code from your plugin so anyone trying to edit it has only the compiled code to work with, which is pretty much entirely useless for editing purposes.

I didn't know that it was permissible to declare variables within begin/end blocks before now, thanks for posting this. That's 2 new things about script syntax I've learned today, which doesn't happen very often anymore (the other being that semicolons in strings are treated as the beginning of a line comment and therefore result in a "mismatched quotes" syntax error).

Cipscis
User avatar
Marlo Stanfield
 
Posts: 3432
Joined: Wed May 16, 2007 11:00 pm

Post » Thu Jan 21, 2010 4:49 pm

If you really want to make your scripts hard to follow, use misleading variable names. Mixing up common variable names like "doOnce", "count" or "target" can make a script take ages to follow.



Well I was laughing at the above part because of it sounding funny...

If you're really dedicated/evil, then you can use FNVEdit to remove the source code from your plugin so anyone trying to edit it has only the compiled code to work with, which is pretty much entirely useless for editing purposes.


That one I don't like.... it's got Nilla****ster written all over it.... not even funny...

I didn't know that it was permissible to declare variables within begin/end blocks before now, thanks for posting this. That's 2 new things about script syntax I've learned today, which doesn't happen very often anymore (the other being that semicolons in strings are treated as the beginning of a line comment and therefore result in a "mismatched quotes" syntax error).

Cipscis



Semicolons what?

Umm I want you to know that I'm kidding about personally trying to make my scripts cryptic.... I would like my scripts to be understandable in fact but, I think sometimes the processes are hard to document well :/
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Thu Jan 21, 2010 1:40 pm

To top it off, make sure to prefix all your floats with 'b', bools with 'r', refs with 'i', and integers with 'f'. That'll really help with the legibility. Also, extraneous parenthesis always help! Another thing one could do is use FormID's whenever possible instead of Editor ID's.
User avatar
Nienna garcia
 
Posts: 3407
Joined: Wed Apr 25, 2007 3:23 am

Post » Thu Jan 21, 2010 11:55 am

Don't forget the ultimate encryption to variable names and Editor IDs, majuscule "i" and minuscule "L" in random order of ~20 characters! I'll personally be using this tactic...

There'll be no doubt about people rippin' my junk. :D
User avatar
KU Fint
 
Posts: 3402
Joined: Mon Dec 04, 2006 4:00 pm

Post » Thu Jan 21, 2010 8:58 am

Umm I want you to know that I'm kidding about personally trying to make my scripts cryptic.... I would like my scripts to be understandable in fact but, I think sometimes the processes are hard to document well :/
I know. I'm kidding too, don't worry.
To top it off, make sure to prefix all your floats with 'b', bools with 'r', refs with 'i', and integers with 'f'. That'll really help with the legibility. Also, extraneous parenthesis always help! Another thing one could do is use FormID's whenever possible instead of Editor ID's.
Extra endifs could also help. Something like this, for example, should be hard to follow:
Spoiler
scn aaaageck1oopz
int testgIob
begin gamemode
label 10
ref bgecko
set TeStGIob to 3
if (((bgecko != bgEcko)+1*3)-12)
set bGECKO to [f]
endif
if TestgIoB != bgeCKO
playerref.additem BGecko TesTgIOb
endif
endif
end
To save you a bit of time, it adds 3 caps to the player's inventory every iteration, but only if NVSE is loaded. Ugh, now I feel dirty...

Cipscis
User avatar
Farrah Lee
 
Posts: 3488
Joined: Fri Aug 17, 2007 10:32 pm

Post » Thu Jan 21, 2010 10:32 am

Don't forget the ultimate encryption to variable names and Editor IDs, majuscule "i" and minuscule "L" in random order of ~20 characters! I'll personally be using this tactic...

There'll be no doubt about people rippin' my junk. :D


I don't believe I could code like that ... !!!! I couldn't tell the variables apart myself. But funny to think about! Kinda, um.

Extra endifs


I thought those were a feature, actually... ask Justin, he'll tell ya.
User avatar
Sabrina Steige
 
Posts: 3396
Joined: Mon Aug 20, 2007 9:51 pm

Post » Thu Jan 21, 2010 2:01 pm

I know. I'm kidding too, don't worry.
Extra endifs could also help. Something like this, for example, should be hard to follow:
Spoiler
scn aaaageck1oopz
int testgIob
begin gamemode
label 10
ref bgecko
set TeStGIob to 3
if (((bgecko != bgEcko)+1*3)-12)
set bGECKO to [f]
endif
if TestgIoB != bgeCKO
playerref.additem BGecko TesTgIOb
endif
endif
end
To save you a bit of time, it adds 3 caps to the player's inventory every iteration, but only if NVSE is loaded. Ugh, now I feel dirty...

Cipscis
Hah! :laugh: This thread is hilarious. Adding a 'glOb' suffix to local variables is brilliant! I think I'll go revise all my scripts now to make sure everything doesn't not make any more (I mean less) sense those who might read them. I might even experiment with reverse indentation.
User avatar
Brentleah Jeffs
 
Posts: 3341
Joined: Tue Feb 13, 2007 12:21 am

Post » Thu Jan 21, 2010 8:30 am

scn aaaageck1oopz
int testgIob
begin gamemode
label 10
ref bgecko
set TeStGIob to 3
if (((bgecko != bgEcko)+1*3)-12)
set bGECKO to [f]
endif
if TestgIoB != bgeCKO
playerref.additem BGecko TesTgIOb
endif
endif
end


this is puke omg.
User avatar
Arnold Wet
 
Posts: 3353
Joined: Fri Jul 07, 2006 10:32 am

Post » Thu Jan 21, 2010 8:01 am

I should see if I can find the list I have (or at least had at some point) of syntax errors that the GECK will accept, like extra "endif" statements, conditions on "else" statements, and "elseif" statements after there's already been an "else" statement.

Cipscis
User avatar
DAVId Bryant
 
Posts: 3366
Joined: Wed Nov 14, 2007 11:41 pm

Post » Thu Jan 21, 2010 6:18 pm

Extra EndIf
I thought those were a feature, actually... ask Justin, he'll tell ya.
Those are my absolute favorite! Every script should have at least two or three, particularly when they have ElseIf/ElseIf/EndIf sections with no 'If' and are reverse-indented. :laugh: If it compiles; it's perfect, right?
User avatar
An Lor
 
Posts: 3439
Joined: Sun Feb 18, 2007 8:46 pm

Post » Thu Jan 21, 2010 8:06 pm

Yep, a high endif:if ratio is a hallmark of a good scripter! They should also be able to use unclear and little-known function aliases such as http://geck.gamesas.com/index.php/, http://geck.gamesas.com/index.php/GetSelf, http://geck.gamesas.com/index.php/DamageObject, and http://geck.gamesas.com/index.php/AddNote.

Calling non-reference functions on references is another great way to confuse readers, particularly if the function reads as though it might be a reference function, like http://geck.gamesas.com/index.php/RewardXP and http://geck.gamesas.com/index.php/RewardKarma.

Cipscis
User avatar
Farrah Lee
 
Posts: 3488
Joined: Fri Aug 17, 2007 10:32 pm

Post » Thu Jan 21, 2010 7:08 pm

	set refvar to this


They should also be able to use unclear and little-known function aliases such as http://geck.gamesas.com/index.php/, http://geck.gamesas.com/index.php/GetSelf, http://geck.gamesas.com/index.php/DamageObject, and http://geck.gamesas.com/index.php/AddNote.

Cipscis


I had wondered...

what... the.. hell..

Now I know!

.... I'd like to know what/how/something that guy knew all this weird [censored] like "this" being an alias for getself... I don't think I saw "this" in Fallout 3's esm (maybe its there but really, I just did not see it in my travels).
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am

Post » Thu Jan 21, 2010 12:48 pm

I've known about that one since Oblivion, although I don't think it's ever been in common use. http://geck.gamesas.com/index.php/DamageObject was the one that really confused me at first in Fallout 3. I've used http://fose.silverlock.org/Fallout3Commands.html of functions from the initial release of Fallout 3 to confirm most aliases.

I couldn't find a list of syntax errors that the GECK will admit, although if I really wanted to (I don't) I could pull one out of my validator. I'm fairly familiar with it though, thanks to doing plenty of work in that department. I don't think I've every used my powers for evil like this before though, haha.

Cipscis
User avatar
TOYA toys
 
Posts: 3455
Joined: Sat Jan 13, 2007 4:22 am

Post » Thu Jan 21, 2010 6:49 am

If you really want to make your scripts hard to follow, use misleading variable names. Mixing up common variable names like "doOnce", "count" or "target" can make a script take ages to follow. If you're really dedicated/evil, then you can use FNVEdit to remove the source code from your plugin so anyone trying to edit it has only the compiled code to work with, which is pretty much entirely useless for editing purposes.

I didn't know that it was permissible to declare variables within begin/end blocks before now, thanks for posting this. That's 2 new things about script syntax I've learned today, which doesn't happen very often anymore (the other being that semicolons in strings are treated as the beginning of a line comment and therefore result in a "mismatched quotes" syntax error).

Cipscis


Don't forget about using NVSE's Label and GoTo bloody everywhere just because you can, no matter if it's supposed to be a loop or not.
User avatar
trisha punch
 
Posts: 3410
Joined: Thu Jul 13, 2006 5:38 am

Post » Thu Jan 21, 2010 3:16 pm

Jumping between blocks as well, naturally. Multiple labels of the same index also help, and I'd be thoroughly impressed if I could see a working script obfuscated to a reasonable degree in this way.

Cipscis

EDIT:

Speaking of blocks, you absolutely must have multiple blocks of the same type. Ideally, different sections of code should be separated into different blocks:
Spoiler
scn aaaageck1oopzint testgIobbegin gamemodelabel 10ref bgeckoset TeStGIob to 3if (((bgecko != bgEcko)+1*3)-12)set bGECKO to [f]endifENDBEGIN gamemodeif TestgIoB != bgeCKO	label 3	playerref.additem BGecko TesTgIOb	endif	elseelseif BGecko ;IMPORTANT!	BgecKo.do 5	goto 10	thisendifend

Cipscis
User avatar
Jessie Butterfield
 
Posts: 3453
Joined: Wed Jun 21, 2006 5:59 pm

Post » Thu Jan 21, 2010 10:31 am

you guys are making my head hurt.

:sadvaultboy:
User avatar
FirDaus LOVe farhana
 
Posts: 3369
Joined: Thu Sep 13, 2007 3:42 am

Post » Thu Jan 21, 2010 6:39 am

This thread is awesome.

.... I'd like to know what/how/something that guy knew all this weird [censored] like "this" being an alias for getself... I don't think I saw "this" in Fallout 3's esm (maybe its there but really, I just did not see it in my travels).


"this" is a commonly used keyword in object-oriented programming languages (Ie. C++) as a pointer to the object the executing code is a member of (sorry, my explanation-fu is weak, so don't blame me if the exact words I used are wrong ;))
User avatar
Mélida Brunet
 
Posts: 3440
Joined: Thu Mar 29, 2007 2:45 am

Post » Thu Jan 21, 2010 9:23 am

Ugh, I despise the use of "do". It took me days to figure out that it stood for DamageObject.
User avatar
FoReVeR_Me_N
 
Posts: 3556
Joined: Wed Sep 05, 2007 8:25 pm

Post » Thu Jan 21, 2010 4:08 pm

Yeah, I agree. Luckily, it's one of the things that my http://www.cipscis.com/fallout/utilities/validator.aspx can "fix". Whenever I'm having trouble following a script, I run it through my validator with "long aliases" and "standardise capitalisation" ticked, which forces all known functions and keywords to use their long aliases, and the capitalisation scheme that I use when writing scripts.

If use of an alias in order to shorten code requires more comments to be added in order to prevent the code from becoming difficult to follow, it's not a very useful alias.

@Weirwynn:
Sounds like a good explanation to me.

Cipscis
User avatar
gary lee
 
Posts: 3436
Joined: Tue Jul 03, 2007 7:49 pm

Next

Return to Fallout: New Vegas