




已阅读5页,还剩64页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 of 69 Code Script Exercises (1- 10)Script Exercises (1- 10) Code for ExperimentsCode for Experiments E-Prime 2002 WorkshopE-Prime 2002 Workshop Files on My DocumentsMy Files on My DocumentsMy ExperimentsWorkshopE-Prime ExperimentsWorkshopE-Prime ExercisesExercises E-Prime Script Exercises 2 of 69 Code E-Prime Code Tutorials q Use of help facility. q Use of Code to Set a Property. q Program flow control. q Use of Code to Set the Stimulus Conditional on a List Attribute. q Using Debug.Print to Report Event Times and debugging. q Use of code to provide cumulative data and exit block when five correct answers in a row. (Optional). q Using code to read a digital IO bit and set digital bit (optional). q Use of Onset Synch to control external hardware (optional). q Use of loop to present frames (optional). q Sample data from a list and delete repeats (optional). 3 of 69 Code Basic Steps to Writing Code 1. Determine what you want your code to do and at what point in the experimental procedure it is to occur. e.g., if you want to set the stimulus to a random number from 1-499, “c.SetAttrib “Stim“, Random(1,499)” 2. Declare any variables that maintain information across multiple executions in the User Code area (display the Script window via the View menu, and select the User Tab). If the variables must be initialized to other than the default values, add an Inline object to the start of the experiment procedure for initialization (e.g., declare an array of real numbers Dim Word(10) As String) 3. Add Inline objects at the appropriate procedure (e.g., session, block, trial) and position in the procedure to execute the code, declare local variables not referenced by other objects, and enter your procedural code. 4. Reference any variables in the List objects (in the experimental context) with c.GetAttrib to get the values and c. SetAttrib to set the values of the variables. Set properties of objects (e.g, TextDisplay.x=0), or execute objects (e.g., TextDisplay.run). Query properties of other objects as needed (e.g., localvariable=Bitmap.RT). 5. Reference results of the code by using attributes in other E-Prime objects (e.g., add “AttributeName” to the text area of a TextDisplay object). 6. Include any debug related printing using the Debug.Print option to check data. In the View menu, select Output, and select the Debug tab. To report when things happened, add “Cstr(Clock.Read) to get the time in milliseconds since the beginning of the experiment. 7. Run the experiment, checking the debug output. 4 of 69 Code Exercise 1: Using E-Basic Online Help The are over 1000 pages of online help for E- Basic. Use the help to find commands, learn their syntax, and get examples on how to use the commands. This short example will show how to find a command (Display.Rectangle) copy an example and run it and how to find things in the E-Basic Help. 5 of 69 Code q 1. Open a new Experiment in E-Studio q 2. Create an InLine object for later use in example to copy code to. Click and drag the Inline Object to the SessionProc q 3. Open Help, Click the Help Menu select E- Basic Help. q 4. Scroll through the list of commands, go to the Display:Graphics Opening E-Basic Help 6 of 69 Code Select Command, Examine Help q 5. Click on “Canvas.Rectangl e (method)” q 6. Examine the help. Check the Syntax, Description, Comments, Example, and See Also 7 of 69 Code Copy Example From Help q 7. Copy the example into the copy buffer q Move cursor to beginning of This sample Move cursor to end example q Click and drag to the end of the example (it will reverse highlight the text) q Copy the example with Ctrl -C or Right click/copy 8 of 69 Code Paste Example Into Experiment q 8. Open the Inline object, paste (type Ctrl-V) the text into the inline object q 9. Check that all lines copied completely, (note first and last lines should be green comment lines) q 10. Run the example it should put up a green square DisplayDisplay 9 of 69 Code Modify Parameters q 11. To learn parameters it is good to change some of the parameters to see if they do what is expected. Change: q width w= 600 q pen color to red q pen width to 40 q 12. Rerun experimentDisplayDisplay The example is in the exercises with the The example is in the exercises with the file name #CodeExercise1-Help.file name #CodeExercise1-Help.eses 10 of 69 Code E-Basic Help - Table of Contents q 13. Open E-Basic help q 14. Select Help Topics q 15. Click Contents tab, look at contents for alphabetic list of commands q Note if you double click on E-Basic and click Welcome you get the command summary q Double click on other topics to expand the listings and browse the table of contents of the commands. The Contents allows you to browse the help. It is particularly The Contents allows you to browse the help. It is particularly helpful for identifying summaries of commands and families of helpful for identifying summaries of commands and families of commands. commands. 11 of 69 Code E-Basic Help - Index q 16. Use the Index to get the specific topic, Click Index, type Special Keys double click topic or press display q 17. Look at special keys listing of how to enter keys such as the ANY. Scroll through to view List of special keys The Index allows you to find specific commands when you know The Index allows you to find specific commands when you know the name of the command or function. the name of the command or function. 12 of 69 Code E-Basic Help - Find q 18. Select the Find Help option. q 19. Search for the cresp correct response designation. q 20. Open up the specification. The Find allows you to find any reference to a string. For The Find allows you to find any reference to a string. For example a parameter of a function may not be in the index but a example a parameter of a function may not be in the index but a Find will locate the help pages that include that string. Find will locate the help pages that include that string. 13 of 69 Code Help Exercise Summary q Use the online help. q When needing a given type of command use the Contents under the Topic E-Basic Welcome. q Use the Index for finding commands of interest when you know the name. q Use the Find if the topic is not in the index but you know a related term. q For new commands it is a good practice to copy the example and run it stand alone before trying to use it in new functions. 14 of 69 Code q Code Exercise 1 Study Questions Could you at this point? q Use the Help to find how to declare an integer type variable? q Find the syntax and an example of the IF command? q Find a command that examines a command which would allow you to pick a member of a text string “red,green,blue,black” with an index to pick the correct word? q Determine how to exit a subroutine early? Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix 15 of 69 Code Code Exercise 2: Use of Code to Set a Property With code you can directly set properties of allowing great flexibility by setting and varying the stimuli. This is a simple example of adding code to display the stimuli in a random location along the x-axis. 16 of 69 Code Use of Code to Set a Property q 1. Open #CodeExercise2-SetProperty.es (My DocumentsMy ExperimentsWorkshopE-Prime Exercises) q 2. Run the experiment, notice the random placement of the stimuli on the screen 17 of 69 Code Edit StimPosition Code q 3. Open the StimPosition Inline object and edit the program to randomly present stimuli along the y-axis BeforeBefore AfterAfter 18 of 69 Code Run And Test Program q 4. Run and test the program q 5. Save as CodeExample2.es 19 of 69 Code Looking Up Properties Of An Object q 6. Examine the properties window of the Probe object in E -Studio. This illustrates most of the properties and how they are set q If not open open the properties window q Scroll through the properties q Determine default value of the font size 20 of 69 Code Getting Help On Object Properties q 7. You can get documentation on the properties either in the E-Prime Reference manual or the Help topics q Open the Help topics q Select Text Display Object Properties Window 21 of 69 Code Examine Properties Set FontSize q 8. Examine the properties specification q 9. Add a command Set the font size to vary in units of 20 points randomly from 20 to 100 points 22 of 69 Code Use Item Function to Choose Option q 10. Setting a property with the Item function. Often there is a need to choose items from a set of items. This is illustrated by selecting the FontName q Use Item$ function to choose the font from a list of items q Add a command to randomly choose the FontName q 11. Run the program examine font size and type 23 of 69 Code Setting Yes/No Explicit List Properties q 11. Set the FontItalic function off/on by selecting 0/1 q 12. Select the color from a list, chose color function ccolor. The function coverts a string containing a color name to the red, green, blue values for the color. (If you click on the ForeColor properties you can see the list of color names). Run the program. Some properties must be set, not as text but as on/off values or through Some properties must be set, not as text but as on/off values or through calls to special functions. For on/off, the value of 1 and 0 are used. calls to special functions. For on/off, the value of 1 and 0 are used. The The ForeColor ForeColor property is an example of a property that needs a property is an example of a property that needs a function to covert names to values (e.g., red, green, blue) for the color. function to covert names to values (e.g., red, green, blue) for the color. 24 of 69 Code Setting 8 Properties of a Text Display q 13. Examine this example. It sets 8 parameters representing 57600 (4x4x5x2x2x3x6x10) possible possible variations of the stimulus in 8 lines of code. (Note this is example #CodeExercise2- SetPropertyMulitpleParameters.es) 25 of 69 Code q Code Exercise 2 Properties Study Questions Could you at this point set properties of objects? q Change the font to bold? q Change background colors of the display? q Set the X position of the Fixation display to be the same as the Probe? Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix 26 of 69 Code Exercise 3 Execution Control Execution flow control allows repetitive actions or conditional actions. In this example we will use a For statement for a repetitive action and an IF statement for conditional actions. If x 10If x 10 ActionAction TrueTrue ActionAction FalseFalse For counter For counter = Start to End= Start to End LoopLoop ActionAction 27 of 69 Code Exercise 3 Execution Control For counter For counter = Start to End= Start to End If x 10If x 10 ActionAction TrueTrue LoopLoop ActionAction If x 10If x 10 ActionAction TrueTrue Examine the code note the: q For next loop q IF conditions The indenting shows the commands in the for loop. 28 of 69 Code Load and Execute q 1. Open #CodeExercise3- ProgramControl.es from My DocumentsMy ExperimentsWorksh opE-Prime Exercises. q 2. Examine the InLine1 code. Note it is #CodeExercise1 -Help.es with a For and If statements. q 3. Run the program see the moving box 29 of 69 Code Add an IF Then q 4. Add the IF Else statements shown q If begins the conditional execution q Then is the true action q Else the False Action q End IF finishes the If Note the comments Note the comments explain the mod explain the mod function to get a function to get a remainder and the remainder and the CColorCColor to set the color to set the color 30 of 69 Code Run Program With If Then q 5. Run the program. Observe the color change. q 6. Change the maximum of the For and add ElseIf instead of Else for 3 states. 31 of 69 Code Run Program q 7. Run program examine results. q 8 Save program as CodeExercise3.ex 32 of 69 Code q Code Exercise 3 Program Control Questions Could you at this point? q Add a loop to present the square in #CodeExercise3-ProgramControl to make the square move up for 1000 iterations, down and be a circle for 1000 iterations, and move horizontally and be an oval. q Find other program control commands and implement a WhileWhen, DoLoop or Case process. q Specify how to leave a For loop early (not covered in exercise but in lecture). Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix 33 of 69 Code Code Exercise 4. Use of Code to Set the Stimulus Conditional on a List Attribute This example uses the “Condition” variable to set the “Stim” variable to a random number and the “Resp” variable to the expected key. This also checks for errors in the typing of the attributes. 34 of 69 Code Open Code Examine Get Attribute q 1. Open #CodeExercise4- ListAttribute.es from My DocumentsMy ExperimentsWorkshop E-Prime Exercises. 2. Examine the code and list and predict what will occur. 35 of 69 Code Run And Check for Error q 3. Run the experiment q Note you will see a message box appear on the last trial to indicate that a coding error has occurred, hit enter. This is intentional to illustrate self checking code. q In this case the Bad Condition = bxlow indicates that a spelling error has been detected in the Condition. 36 of 69 Code Correct Errors q 5. Open List1 and edit bxlow to below. BeforeBeforeAfter After 37 of 69 Code Edit RandomNumberGenerate q 6. Open RandomNumberGenerate and edit the conditions to select a number for below 1-4, above 6-9. BeforeBefore AfterAfter 38 of 69 Code Edit Instructions q 7. Edit display instructions located on the Fixation display. BeforeBefore AfterAfter 39 of 69 Code Run and Test Program q 8. Save as CodeExample4.es. q 9. Run to test the program, note the random numbers selected are now between 1-9. 40 of 69 Code q Code Exercise 4 Attributes Questions Could you at this point? q Use Code to set the attribute of font color based on the Condition? q Explain the difference in using code to set an attribute and setting an attribute and setting the property of the attribute using the attribute syntax? q Predict what would happen if an attribute is set multiple times in the same procedure? Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix 41 of 69 Code Exercise 5: Using Debug.Print to Report Event Times Use the Debug.Print command to write debug data during the running of the experiment to monitor when fast actions occur (e.g., OnsetTime of an object). Note an Object.OnsetTime records when an output event takes place. The results are shown in the Output window available on the View menu. 42 of 69 Code Run Debug.Print Exercise q 1. Open #CodeExercise5-DebugPrint.es (My DocumentsMy ExperimentsWorkshopE-Prime Exercises). q 2. Run the experiment, note the use of the RandomNumberGenerate code. 43 of 69 Code View Output Window q 3. View Output window located at the bottom of the screen. Click on View menu and select Output. 44 of 69 Code Copy and Clear Debug Output q 4. You can copy the output to the copy buffer with a right click in the window and copy. You can clear it also with the right click (otherwise the output is appended). Copy the output and paste it into Excel. This is useful for using Excel to check timing issues such as the time between stimuli. q Select all the output with click start and drag to end q Copy q Clear the information q 5. Open Excel q Select first cell q Paste the copied items q Calculate onset time to onset time Onset time enter in Cell F1 = A2-A1 45 of 69 Code Edit Debug.Print q 6. Examine and edit DebugPrint note: q The “t” puts a tab in the string (which causes tab to new column in Excel spreadsheet in copy q The & concatenates strings q The _ at the end of a line continues a line q 7. Add an output of a Probe.RT to report the response time in the output window. BeforeBefore AfterAfter 46 of 69 Code View Output Window q 5. Run program and view Output window, note that the Prob.OnsetTime is now included in the Output window. q 6. Save as CodeExample4.es. BeforeBeforeAfterAfter 47 of 69 Code q Code Exercise 5 Debug.Print Study Questions Could you at this point? q Output the Condition Attribute? q If you had a fast loop presenting stimuli every 14 ms how might you debug.print to see what the stimuli were? q If you had a 2 monitor computer and you ran the experiment on the primary monitor and the Output window on the second monitor, what do you think you would see during the run? Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix 48 of 69 Code Code Example 6. Use of code to provide cumulative data about the trial number to the subject Code that maintains static variables typically must be declared in the User script, initiated in the beginning of the experiment, and updated during the trial procedure. 49 of 69 Code Run Trial Counter Program q 1. Open #CodeExercise6-CumulativeData.es (My DocumentsMy ExperimentsWorkshopE- Prime Exercises). q 2. Run the experiment, note the TrialCounter on the Probe display. 50 of 69 Code Declare a Global Variable q 3. Open the Script window via the View menu. q 4. Declare variable in the User Script window. BeforeBefore AfterAfter 51 of 69 Code Initialize Variable q 5. Initialize the number of correct responses in a row by setting the variable to 0 as was done for the total number of trials. BeforeBefore AfterAfter 52 of 69 Code Add Code to Check Corrects in Row And Set Count q 6. Open the TotalTrialCounterCode q 7. Set the Attribute TotalCurrentRun to the g_NTotalCorrectRun q 8. Add Code that q if g_nTotalCorrectRun = 5 Then Exit Sub (This will exit the TrialProc whenever the number correct is 5 or more). 53 of 69 Code Add Display Of Corrects In A Row q 7. Open Fixation object. Add Total Correct in Row TotalCorrectRun To show number correct in a row. 54 of 69 Code Calculate Correct Run q 8. Add a InLine object after Probe q 9. Rename It CalculateRunCor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届江苏省镇江市宜城中学九年级英语第一学期期末经典模拟试题含解析
- 高杆早樱苗木供应合同3篇
- 高中急救知识培训班课件
- 高中国防教育课件
- AI行业市场前景及投资研究报告:AIDC建设产业加速迭代
- 高三二轮农业课件
- 2026届高考地理一轮复习课件 课时55 交通运输布局对区域发展的影响
- 王蒙《保证书面形式》建筑工程担保合同
- 离婚协议书范本:财产分割与子女抚养协议模板
- 离婚协议书模板:包含婚前财产协议内容
- 2025年全国新高考英语II卷试题解析及复习备考策略(课件)
- 儿童上呼吸道健康管理
- 数字成瘾机制研究-洞察及研究
- 海事英语阅读 课件Unit 9 Text A Types of Maritime Vessels
- 2025科技公司研发部门劳动合同范本
- DB32-T 4264-2022 金属冶炼企业中频炉使用安全技术规范
- 2024-2025学年统编版(2024)初中历史七年级下册(全册)教学设计(附目录P162)
- 统编版高中政治选择性必修3《逻辑与思维》期末综合测试卷(含答案解析)
- 国网安规培训课件
- 干部教育培训工作条例解读
- 机械设计方案评审
评论
0/150
提交评论