Scripts / No function called homemade_ script every time I try a custom script

Author
Message
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 16th Jun 2014 22:58
I finally decided to take a step back from designing models and scenery to play with the Scripts. There's quite a few good ones here on the forums but every time I try to use one in my game I get the error message " no function called (whatever the script name is)" and test game crashes. I copied and pasted the scripts into notepad ++ and save them as lua and put them in the proper directory so I'm not sure what I'm doing wrong. Any advice would be very appreciated
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 16th Jun 2014 23:31
well a mistake I made was having the script saved as lua but it was a txt document, though im not sure how notepad++ works I only used notepad, which needed to be changed to all files instead of .txt when saving.

also make sure this following line is at the top just above the "script name here"_main(e)

function "script name here"_init(e)
end

this helps custom scripts work also.

imno scripter though and cant help further than that sorry m8 good luck

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 17th Jun 2014 00:50
almightyhood - is correct.. I fell into this same trap saving with notepad.

The other important thing is to use an editor that has a Lua syntax color display.
It makes the script much easier to read and then understand...

I use LuaDevelomentTools.exe part of the Eclipse Lua download...

but there are many others.. they are free downloads...
Find one your happy with and you will quickly pick it up..

Also when you post a question it helps if you show the script you are having a problem with.
Use the (code) button to show your code sample..then choose the (code lang=lua) button
Paste or write your code after the (code lang=lua) line, that will be automatically added to your post
Also use plenty of -- Rems to help explain your code, as your code gets bigger you will be glad to have rems.
the 2 -- are the rem command
IMPORTANT - don't forget to close your code block by adding this
(/code) but use square brackets instead of curly brackets.. I had to use curly because if I uses the square
ones then my script block would not show.. ( gee I'm making this worse.. hope it make sense )

see my example..

PM
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 17th Jun 2014 02:18
The code I was trying to use was this I was trying to put a radio in my level that would play a song when you approached it and would fade away when you left the area. Although every code I've tried has given me problems. I assume that code was complete when I copied and pasted it but maybe it needs more work. Here's the code I was trying.:local playingsound = 0

function localsound_init(e)
end
function localsound_main(e)

PlayerDX = g_Entity[9]['x'] - g_PlayerPosX; PlayerDY = g_Entity[9]['y'] - g_PlayerPosY; PlayerDZ = g_Entity[9]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

if PlayerDist < 600 then
if playingsound == 0 then
LoopSound(e,0);
playingsound = 1
end

else
if playingsound == 1 then
--Destroy(e,0);
StopSound(e,0)
playingsound = 0

end
end
end
PM
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 17th Jun 2014 02:21
Sorry, I click the code button to display the code but it didn't display right. By the way, thanks for the help!
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 17th Jun 2014 02:46
you click the lua code button twice once before entering your code once after

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 17th Jun 2014 02:55

Sorry about that! Here's the code. Thanks for the tip.
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 17th Jun 2014 03:16
your welcome m8

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 17th Jun 2014 04:28 Edited at: 17th Jun 2014 04:36
With this as your code




The file name should be localsound.lua. You stated already that its in the correct directory and its saved as the lua type. If the name is correct, there should be no issues. Ill give it a whirl and see if it does it to me as well.

[img]http://files.enjin.com/191696/UA Members Banners/Imchasinyou.jpg[/img]
PM
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 17th Jun 2014 04:54 Edited at: 17th Jun 2014 04:56
OK, after testing this, I can say that it in fact works. if the attachments work, it will be attached and you can then download it and place into your scriptbank folder. I had toobviously change the entity numbers but that can easily be fixed by you.

[img]http://files.enjin.com/191696/UA Members Banners/Imchasinyou.jpg[/img]
PM
AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 17th Jun 2014 06:25
A quick notepad++ tip, when you start a new file look for a menu at the top that says language, go to L then lua. It will automatically dobsyntax highlighting then and will also automatically save as a lua file

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 17th Jun 2014 12:54
Quote: "A quick notepad++ tip, when you start a new file look for a menu at the top that says language, go to L then lua. It will automatically dobsyntax highlighting then and will also automatically save as a lua file"


Its this kind of information that keeps me lookign in the forums. Great tip. I did not know that!

[img]http://files.enjin.com/191696/UA Members Banners/Imchasinyou.jpg[/img]
PM
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 17th Jun 2014 16:22
The script works now from your attachment, thank you imchasinyou. I didnt know the name of the script affected if it would function so I just named it whatever I wanted. Also good notepad ++ tip aushadow, thank you. I'm a master when it comes to writing scripts for glovepie but lua, not so much. I understand what the script says and how to tweak it a little but not how to write it from scratch. Thanks again!
PM
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 17th Jun 2014 17:28
mguy1122@
Thanks for your thread I learnt 2 more things here..

allmightyhood@
Thanks for the [press the code button again after your code].I didn't know that

AuShadow@
Thanks for the notepad++ tip I am now going to use this for my lua edits..

I can code... but I'm a forum novice. I am gradually learning how to do things on here...
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 17th Jun 2014 19:53
your welcome m8

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
mguy1122
Game Guru Backer
11
Years of Service
User Offline
Joined: 5th Mar 2013
Playing: witcher 3
Posted: 17th Jun 2014 22:18 Edited at: 17th Jun 2014 22:21
No problem! I'm just glad these the people on these forums are so helpful. Other forums I've been on, the people aren't so willing to help. Much appreciated!
PM
AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 17th Jun 2014 22:53
another Notepad++ tip for those intrested is that when you have multiple scripts open within Notepad++ and you find yourself switching between 2 fairly often, a neat thing you can do is right click the TAB in the top left of the windowed are and then select Move To Other View and then you can have 2 scripts open on the one page within in the same program / window, there is also clone to other view and some more stuff there but i can't give away everything and take the fun out of exploring a program

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 18th Jun 2014 03:03
Quote: "and some more stuff there but i can't give away everything and take the fun out of exploring a program
"


Exploring software and trying to see what does what is what ruins software for me. I always screw up something and then Im frustrated at myself and give up. . . . lol

[img]http://files.enjin.com/191696/UA Members Banners/Imchasinyou.jpg[/img]
PM

Login to post a reply

Server time is: 2024-09-08 03:47:06
Your offset time is: 2024-09-08 03:47:06