Scritp Dont Work can anyone help me?

Questions about level scripting

Moderators: Main Administator, Moderator, Global Moderator

Post Reply
User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 1:35 pm

I made a new level where i have scritp press W,A,S,D Move the Block and script Dont Work. Can Help me?

Script:

function OnLoad()
  Game.SetKeyHook("W", "PutTheBlock")
  return true
end

function PutTheBlock()
  x, y = Game.GetPlayerPosition()
  Game.SetBlockPos("Block0", x, y -0.5 0)
end

function OnLoad()
  Game.SetKeyHook("A", "PutTheBlock")
  return true
end

function PutTheBlock()
  x, y = Game.GetPlayerPosition()
  Game.SetBlockPos("Block0", x, y -0 -0.5)
end

function OnLoad()
  Game.SetKeyHook("S", "PutTheBlock")
  return true
end

function PutTheBlock()
  x, y = Game.GetPlayerPosition()
  Game.SetBlockPos("Block0", x, y -0.5 -0)
end

function OnLoad()
  Game.SetKeyHook("D", "PutTheBlock")
  return true
end

function PutTheBlock()
  x, y = Game.GetPlayerPosition()
  Game.SetBlockPos("Block0", x, y -0 0.5)
end

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 2:54 pm

You can't use function OnLoad three times, you have to put it into one function OnLoad ;)
And you have to find different names, not always PutTheBlock ;P
Last edited by SeRe on Sat Jan 18, 2014 2:56 pm, edited 1 time in total.

User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Re: Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 2:57 pm

But i try just whrite:

function OnLoad()
  Game.SetKeyHook("M", "PutTheBlock")
  return true
end

function PutTheBlock()
  x, y = Game.GetPlayerPosition()
  Game.SetBlockPos("Block0", x, y -2.5 -1)
end

And it dont work too.

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 3:05 pm

When I'm at my computer, I'll edit your scipt...
But btw you have to write "x,y = GetBlockPos("Block0")"

But before you post a topic at the forum, you should read the wiki first...
Last edited by SeRe on Sat Jan 18, 2014 3:07 pm, edited 1 time in total.

User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Re: Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 3:47 pm

I Read Wiki... and i copy what is whrited there.

And:

function OnLoad()
  Game.SetKeyHook("M", "PutTheBlock")
  return true
end

function PutTheBlock()
  x, y = Game.GetPlayerPosition()
  x, y = GetBlockPos("Block0", x, y -2.5 -1)
end

i whrited and when i press M  so it close Xm and whrite :

Fatal exception occured: failed to invoke (void) PutThe BLock(): [string""]:7: attempt to call global 'GetBlockPos' (a nil value) Consult the file xmoto.log for more information about wat might has occured.

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 3:52 pm

you have to write Block0 ={} at the begining of the script...
didn't know that you don't know this... :P

User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Re: Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 4:00 pm

Dont work -.- .
And i have already one level created where this script work.
I dont know why dont work on this too.

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 4:23 pm

Like I said, I'll post a working script when I'm at home...
Last edited by SeRe on Sat Jan 18, 2014 5:20 pm, edited 1 time in total.

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 6:01 pm

That one works:
Block0 = {}
x,y = 0,0





function OnLoad()
  Game.SetKeyHook("W", "WPutTheBlock")
  Game.SetKeyHook("A", "APutTheBlock")
  Game.SetKeyHook("S", "SPutTheBlock")
  Game.SetKeyHook("D", "DPutTheBlock")
  return true
end

function WPutTheBlock()
  x, y = Game.GetBlockPos("Block0")
  Game.SetBlockPos("Block0", x, y + 0.5)
end



function APutTheBlock()
  x, y = Game.GetBlockPos("Block0")
  Game.SetBlockPos("Block0", x - 0.5, y)
end


function SPutTheBlock()
  x, y = Game.GetBlockPos("Block0")
  Game.SetBlockPos("Block0", x, y - 0.5)
end



function DPutTheBlock()
  x, y = Game.GetBlockPos("Block0")
  Game.SetBlockPos("Block0", x + 0.5, y)
end

If that's what you want...
Last edited by SeRe on Sat Jan 18, 2014 6:05 pm, edited 1 time in total.

User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Re: Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 6:17 pm

Dont Work too.

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 6:23 pm

Have you changed the block properties to dynamic block ?

User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Re: Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 6:54 pm

[quote="SeRe"]
Have you changed the block properties to dynamic block ?
[/quote]

Yes, and it still dont work. I try Reinstall inkscape because i have some problems with scritps.

User avatar
Wesker
Xmoto Player
Xmoto Player
Posts: 52
Joined: Thu Oct 31, 2013 12:55 pm

Re: Scritp Dont Work can anyone help me?

Post by Wesker » Sat Jan 18, 2014 7:18 pm

[quote="Wesker"]
[quote="SeRe"]
Have you changed the block properties to dynamic block ?
[/quote]

Yes, and it still dont work. I try Reinstall inkscape because i have some problems with scritps.
[/quote]

Ok it work. And dont know you maybe how to set Game.keyhook F change block to if i press F i change to BLock 2 again F to block 3 and again F to block 1 and again and again?

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 8:09 pm

You have to use if check == 1 then, but please learn scripting before you ask me everything ;P

User avatar
SeRe
Administrator
Administrator
Posts: 108
Joined: Thu Oct 03, 2013 7:10 pm
Location: Austria
Contact:

Re: Scritp Dont Work can anyone help me?

Post by SeRe » Sat Jan 18, 2014 8:13 pm

make something like that:
function ChangeBlock()
if check0 == 1 then
check0 = 0
check1 = 1
else
if check1 == 1then
check1 = 0
check0 = 1
end
end (don't know exactly how many ends are needed, so just try it)

Post Reply

Return to “Script a Level”

Who is online

Users browsing this forum: No registered users and 1 guest