Home   Help Search Login Register  

Author Topic: Beginner scripter  (Read 1205 times)

0 Members and 1 Guest are viewing this topic.

Leodinas

  • Guest
Beginner scripter
« on: 30 Mar 2005, 05:08:32 »
I am just learning here, and am in the process of writing my first script following these directions:

Your first script
Below is an example of an extremely simple script. This script will take in a string value and output that text as a hint.
************
;hintmaker.sqs
;This script takes a string value and generates a hint from it

_mystring = _this select 0
hint _mystring
exit
************

NOW IT'S YOUR TURN.
Now that we've discussed the above script, lets create this script on our machines and actually use it.
1. First, you must create a scenario and save it, so you have a working directory to place your script in. You will be placing all your scripts in the root directory of your mission. Create a simple scenario with just one individual, the player, and save your scenario as "script_test"
2. ALT-TAB to the desktop. Find the mission directory for your mission and create a text file called hintmaker.sqs. Your missions directory is located in: OFP1\users\MyUserName\missions\intro.Script_Test
3. Open the script file, and type in the above script. Check for typos and save your work. You can skip the comments if you like. Just remember that comments are your friend when you make your own scripts.
4. As with all scripts, they may be executed from the individual's init field, triggers, waypoints and other scripts. As an example, let's execute our script with a trigger. Go back to the editor and create a trigger with the following fields:

Axis a:    0
Axis b:    0
Countdown:      Min: 3     Mid: 3     Max: 3
Condition:    true
Activation:       ["Have a nice day"] exec "hintmaker.sqs"
Type:   Switch
Text:   show a hint

4. Go ahead and preview the scenario. After three seconds, your hint will appear with a resounding "ding!"  If all went well, you have successfully created and used your first script.



I am running version 1.46 and I followed all of these directions. Upon making the trigger, it doesn't seem to detect the hintmaker script. I thought this was going to be an easy tutorial for scripting... This trial and error stuff is tedious. The sqs file is still saved as a text document... could that be part of it? How do I change it if that is the problem?

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:Beginner scripter
« Reply #1 on: 30 Mar 2005, 05:15:01 »
You need to save it as a .sqs file. To do so, click on the "Save as type:" bar and change it to "All Files". Then type in the "File name:" bar
Code: [Select]
hintmaker.sqs
and it should now work. Also remember to delete the text file.
« Last Edit: 30 Mar 2005, 05:16:16 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Dubieman

  • Guest
Re:Beginner scripter
« Reply #2 on: 30 Mar 2005, 05:59:48 »
Is that John Gustafson's 2nd scripting tutorial that you are using?

Just out of curiosity, cause I thought that tut went through .sqs like Tyger is saying before it got to scripting.

I was a beginner too at one time... Still learning... ::) ;D ;D

And one of the best starting tools is Chris Henderson's OFP Script Editor in the OFPEC editor depot. Very useful. ;)
« Last Edit: 30 Mar 2005, 06:00:23 by GuiltyRoachKillar »

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Beginner scripter
« Reply #3 on: 30 Mar 2005, 10:19:00 »
Yea, GRK is still n00bier than I am. ;D

Chris' Editor is very usefull. They say it's just for n00bs, but hey, I still use it. I use it to script HTML and PHP too, which doesn't work very well... At least it can do it! ;D

:beat: *Gets Shot* :beat:

Offline RujiK

  • Members
  • *
  • KoKo Puh-Fizzles!
Re:Beginner scripter
« Reply #4 on: 30 Mar 2005, 18:51:18 »
Just a question, but why make a hint maker? Why not just do Hint"Duh!"? It seems odd.

You could make a script for every command it just seems really lame.
(Ie Setbehaviourmaker)
I like your approach, lets see your departure.
Download the New Flashlight Script!

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Beginner scripter
« Reply #5 on: 30 Mar 2005, 19:55:58 »
Just a question, but why make a hint maker? Why not just do Hint"Duh!"? It seems odd.

You could make a script for every command it just seems really lame.
(Ie Setbehaviourmaker)

Because he's learning to script... So you mean your very first mission that you made via a tutorial (like, place three units and put out a WP and then it's done) is supposed to be good?

:beat: *Gets Shot* :beat:

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Beginner scripter
« Reply #6 on: 30 Mar 2005, 20:51:40 »
@Rujik

Its a tutorial for beginners at scripting.

In just about any computer language tutorial, 9 times out of 10 the first little example you are shown is the 'Hello World' program.
All it does is print 'Hello World' on your screen.

The above example is similar, it will also print 'Hello World' if that is what you pass to the script.


Planck
I know a little about a lot, and a lot about a little.

Leodinas

  • Guest
Re:Beginner scripter
« Reply #7 on: 30 Mar 2005, 23:12:30 »
Thank you everyone for your speed in replying. I had a feeling that this was the problem when I couldn't get the correct looking icon. Sure enough, I checked the name of the file: hintmaker.sqs.txt and said: "This is wrong."

I just wasn't sure how to correct this since this is ny first time with a text file. After you explained it, I was able to do it with ease, and I now understand how these scripts work. I suspect more questions will come as I learn more.

A few years ago in college I took a C++ programming class, and enjoyed it, but didn't know how it would aid my History Masters and secondary education... Now I understand if/then use, logic, and truth tables much better then the average beginner. Therefore, I know what to expect from the scripts, how to construct them, and how to use them in the editor... Now I just need to learn that language so I can create them.

I need some positive reinforcement, here!

Dubieman

  • Guest
Re:Beginner scripter
« Reply #8 on: 30 Mar 2005, 23:53:06 »
Positive reinfocement?
errr

Good job, go get um tiger! ;D ::) :D


Quote
Yea, GRK is still n00bier than I am.

Hmmm....bested by a 14 year old....
Therapy, must get therapy... :-X